react-router 7.16.0 → 8.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1007
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1645 -1635
- package/dist/development/index-react-server.js +2880 -3642
- package/dist/development/index.d.ts +43 -1475
- package/dist/development/index.js +37 -2621
- package/dist/development/lib/actions.js +62 -0
- package/dist/development/lib/components.d.ts +1022 -0
- package/dist/development/lib/components.js +835 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2042 -0
- package/dist/development/lib/dom/lib.js +1259 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +196 -0
- package/dist/development/lib/dom/ssr/components.js +579 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/development/lib/dom/ssr/errors.js +36 -0
- package/dist/development/lib/dom/ssr/fallback.js +28 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +45 -0
- package/dist/development/lib/dom/ssr/server.js +68 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +153 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1386 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +371 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +113 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2981 -0
- package/dist/development/lib/router/utils.d.ts +942 -0
- package/dist/development/lib/router/utils.js +791 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +599 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +388 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +95 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +351 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +31 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/{production/register-CNAx3TXj.d.ts → development/lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1007
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1645 -1635
- package/dist/production/index-react-server.js +2871 -3642
- package/dist/production/index.d.ts +43 -1475
- package/dist/production/index.js +37 -2621
- package/dist/production/lib/actions.js +62 -0
- package/dist/production/lib/components.d.ts +1022 -0
- package/dist/production/lib/components.js +835 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2042 -0
- package/dist/production/lib/dom/lib.js +1259 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +196 -0
- package/dist/production/lib/dom/ssr/components.js +579 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/production/lib/dom/ssr/errors.js +36 -0
- package/dist/production/lib/dom/ssr/fallback.js +21 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +45 -0
- package/dist/production/lib/dom/ssr/server.js +68 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +153 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1371 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +371 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +113 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2981 -0
- package/dist/production/lib/router/utils.d.ts +942 -0
- package/dist/production/lib/router/utils.js +782 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +599 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +388 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +95 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +351 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +31 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/{development/register-CNAx3TXj.d.ts → production/lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
- package/docs/explanation/backend-for-frontend.md +50 -0
- package/docs/explanation/code-splitting.md +77 -0
- package/docs/explanation/concurrency.md +135 -0
- package/docs/explanation/form-vs-fetcher.md +292 -0
- package/docs/explanation/hot-module-replacement.md +137 -0
- package/docs/explanation/hydration.md +14 -0
- package/docs/explanation/index-query-param.md +86 -0
- package/docs/explanation/index.md +4 -0
- package/docs/explanation/lazy-route-discovery.md +78 -0
- package/docs/explanation/location.md +6 -0
- package/docs/explanation/progressive-enhancement.md +150 -0
- package/docs/explanation/race-conditions.md +88 -0
- package/docs/explanation/react-transitions.md +160 -0
- package/docs/explanation/route-matching.md +7 -0
- package/docs/explanation/server-client-execution.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +465 -0
- package/docs/explanation/special-files.md +16 -0
- package/docs/explanation/state-management.md +524 -0
- package/docs/explanation/styling.md +87 -0
- package/docs/explanation/type-safety.md +82 -0
- package/docs/how-to/accessibility.md +44 -0
- package/docs/how-to/client-data.md +199 -0
- package/docs/how-to/data-strategy.md +317 -0
- package/docs/how-to/error-boundary.md +231 -0
- package/docs/how-to/error-reporting.md +134 -0
- package/docs/how-to/fetchers.md +307 -0
- package/docs/how-to/file-route-conventions.md +410 -0
- package/docs/how-to/file-uploads.md +217 -0
- package/docs/how-to/form-validation.md +120 -0
- package/docs/how-to/headers.md +164 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +556 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +728 -0
- package/docs/how-to/navigation-blocking.md +233 -0
- package/docs/how-to/optimize-revalidation.md +12 -0
- package/docs/how-to/pre-rendering.md +225 -0
- package/docs/how-to/presets.md +103 -0
- package/docs/how-to/react-server-components.md +899 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +100 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +30 -0
- package/docs/how-to/server-bundles.md +66 -0
- package/docs/how-to/spa.md +120 -0
- package/docs/how-to/status.md +63 -0
- package/docs/how-to/suspense.md +132 -0
- package/docs/how-to/using-handle.md +117 -0
- package/docs/how-to/view-transitions.md +237 -0
- package/docs/how-to/webhook.md +50 -0
- package/docs/index.md +39 -0
- package/docs/start/data/actions.md +138 -0
- package/docs/start/data/custom.md +198 -0
- package/docs/start/data/data-loading.md +44 -0
- package/docs/start/data/index.md +4 -0
- package/docs/start/data/installation.md +52 -0
- package/docs/start/data/navigating.md +12 -0
- package/docs/start/data/pending-ui.md +12 -0
- package/docs/start/data/route-object.md +248 -0
- package/docs/start/data/routing.md +281 -0
- package/docs/start/data/testing.md +8 -0
- package/docs/start/declarative/index.md +4 -0
- package/docs/start/declarative/installation.md +43 -0
- package/docs/start/declarative/navigating.md +133 -0
- package/docs/start/declarative/routing.md +237 -0
- package/docs/start/declarative/url-values.md +65 -0
- package/docs/start/framework/actions.md +175 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +96 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +42 -0
- package/docs/start/framework/navigating.md +182 -0
- package/docs/start/framework/pending-ui.md +142 -0
- package/docs/start/framework/rendering.md +59 -0
- package/docs/start/framework/route-module.md +527 -0
- package/docs/start/framework/routing.md +362 -0
- package/docs/start/framework/testing.md +133 -0
- package/docs/start/index.md +4 -0
- package/docs/start/modes.md +201 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +31 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/remix.md +403 -0
- package/docs/upgrading/router-provider.md +442 -0
- package/docs/upgrading/v6.md +379 -0
- package/package.json +44 -87
- package/dist/development/browser-D3uq9sI1.d.ts +0 -318
- package/dist/development/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/development/chunk-IBI7OMNB.js +0 -1363
- package/dist/development/chunk-QUQL4437.mjs +0 -11529
- package/dist/development/chunk-S54KXAEJ.mjs +0 -2585
- package/dist/development/chunk-SRID2YZ2.js +0 -10229
- package/dist/development/chunk-XEJDWL2B.js +0 -188
- package/dist/development/context-m8rizgnE.d.mts +0 -1771
- package/dist/development/data-D4xhSy90.d.ts +0 -1732
- package/dist/development/data-U8FS-wNn.d.mts +0 -1732
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1008
- package/dist/development/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/development/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2703
- package/dist/development/index-react-server.mjs +0 -3780
- package/dist/development/index.d.mts +0 -1478
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-CqK96Zfk.d.mts +0 -30
- package/dist/production/browser-D3uq9sI1.d.ts +0 -318
- package/dist/production/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/production/chunk-EAQNHM3N.js +0 -188
- package/dist/production/chunk-NALGHHKE.mjs +0 -2585
- package/dist/production/chunk-Q65P7S7Y.mjs +0 -11529
- package/dist/production/chunk-SKEDDLRM.js +0 -1363
- package/dist/production/chunk-Y7DNFQZP.js +0 -10229
- package/dist/production/context-m8rizgnE.d.mts +0 -1771
- package/dist/production/data-D4xhSy90.d.ts +0 -1732
- package/dist/production/data-U8FS-wNn.d.mts +0 -1732
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1008
- package/dist/production/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/production/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2703
- package/dist/production/index-react-server.mjs +0 -3780
- package/dist/production/index.d.mts +0 -1478
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-CqK96Zfk.d.mts +0 -30
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { Deferred, SUPPORTED_ERROR_TYPES } from "./utils.js";
|
|
12
|
+
//#region vendor/turbo-stream-v2/unflatten.ts
|
|
13
|
+
const globalObj = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
|
|
14
|
+
function unflatten(parsed) {
|
|
15
|
+
const { hydrated, values } = this;
|
|
16
|
+
if (typeof parsed === "number") return hydrate.call(this, parsed);
|
|
17
|
+
if (!Array.isArray(parsed) || !parsed.length) throw new SyntaxError();
|
|
18
|
+
const startIndex = values.length;
|
|
19
|
+
for (const value of parsed) values.push(value);
|
|
20
|
+
hydrated.length = values.length;
|
|
21
|
+
return hydrate.call(this, startIndex);
|
|
22
|
+
}
|
|
23
|
+
function hydrate(index) {
|
|
24
|
+
const { hydrated, values, deferred, plugins } = this;
|
|
25
|
+
let result;
|
|
26
|
+
const stack = [[index, (v) => {
|
|
27
|
+
result = v;
|
|
28
|
+
}]];
|
|
29
|
+
let postRun = [];
|
|
30
|
+
while (stack.length > 0) {
|
|
31
|
+
const [index, set] = stack.pop();
|
|
32
|
+
switch (index) {
|
|
33
|
+
case -7:
|
|
34
|
+
set(void 0);
|
|
35
|
+
continue;
|
|
36
|
+
case -5:
|
|
37
|
+
set(null);
|
|
38
|
+
continue;
|
|
39
|
+
case -2:
|
|
40
|
+
set(NaN);
|
|
41
|
+
continue;
|
|
42
|
+
case -6:
|
|
43
|
+
set(Infinity);
|
|
44
|
+
continue;
|
|
45
|
+
case -3:
|
|
46
|
+
set(-Infinity);
|
|
47
|
+
continue;
|
|
48
|
+
case -4:
|
|
49
|
+
set(-0);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (hydrated[index]) {
|
|
53
|
+
set(hydrated[index]);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const value = values[index];
|
|
57
|
+
if (!value || typeof value !== "object") {
|
|
58
|
+
hydrated[index] = value;
|
|
59
|
+
set(value);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) if (typeof value[0] === "string") {
|
|
63
|
+
const [type, b, c] = value;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "D":
|
|
66
|
+
set(hydrated[index] = new Date(b));
|
|
67
|
+
continue;
|
|
68
|
+
case "U":
|
|
69
|
+
set(hydrated[index] = new URL(b));
|
|
70
|
+
continue;
|
|
71
|
+
case "B":
|
|
72
|
+
set(hydrated[index] = BigInt(b));
|
|
73
|
+
continue;
|
|
74
|
+
case "R":
|
|
75
|
+
set(hydrated[index] = new RegExp(b, c));
|
|
76
|
+
continue;
|
|
77
|
+
case "Y":
|
|
78
|
+
set(hydrated[index] = Symbol.for(b));
|
|
79
|
+
continue;
|
|
80
|
+
case "S":
|
|
81
|
+
const newSet = /* @__PURE__ */ new Set();
|
|
82
|
+
hydrated[index] = newSet;
|
|
83
|
+
for (let i = value.length - 1; i > 0; i--) stack.push([value[i], (v) => {
|
|
84
|
+
newSet.add(v);
|
|
85
|
+
}]);
|
|
86
|
+
set(newSet);
|
|
87
|
+
continue;
|
|
88
|
+
case "M":
|
|
89
|
+
const map = /* @__PURE__ */ new Map();
|
|
90
|
+
hydrated[index] = map;
|
|
91
|
+
for (let i = value.length - 2; i > 0; i -= 2) {
|
|
92
|
+
const r = [];
|
|
93
|
+
stack.push([value[i + 1], (v) => {
|
|
94
|
+
r[1] = v;
|
|
95
|
+
}]);
|
|
96
|
+
stack.push([value[i], (k) => {
|
|
97
|
+
r[0] = k;
|
|
98
|
+
}]);
|
|
99
|
+
postRun.push(() => {
|
|
100
|
+
map.set(r[0], r[1]);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
set(map);
|
|
104
|
+
continue;
|
|
105
|
+
case "N":
|
|
106
|
+
const obj = Object.create(null);
|
|
107
|
+
hydrated[index] = obj;
|
|
108
|
+
for (const key of Object.keys(b).reverse()) {
|
|
109
|
+
const r = [];
|
|
110
|
+
stack.push([b[key], (v) => {
|
|
111
|
+
r[1] = v;
|
|
112
|
+
}]);
|
|
113
|
+
stack.push([Number(key.slice(1)), (k) => {
|
|
114
|
+
r[0] = k;
|
|
115
|
+
}]);
|
|
116
|
+
postRun.push(() => {
|
|
117
|
+
obj[r[0]] = r[1];
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
set(obj);
|
|
121
|
+
continue;
|
|
122
|
+
case "P":
|
|
123
|
+
if (hydrated[b]) set(hydrated[index] = hydrated[b]);
|
|
124
|
+
else {
|
|
125
|
+
const d = new Deferred();
|
|
126
|
+
deferred[b] = d;
|
|
127
|
+
set(hydrated[index] = d.promise);
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
case "E":
|
|
131
|
+
const [, message, errorType] = value;
|
|
132
|
+
let error = errorType && globalObj && SUPPORTED_ERROR_TYPES.includes(errorType) && errorType in globalObj && typeof globalObj[errorType] === "function" ? new globalObj[errorType](message) : new Error(message);
|
|
133
|
+
hydrated[index] = error;
|
|
134
|
+
set(error);
|
|
135
|
+
continue;
|
|
136
|
+
case "Z":
|
|
137
|
+
set(hydrated[index] = hydrated[b]);
|
|
138
|
+
continue;
|
|
139
|
+
default:
|
|
140
|
+
if (Array.isArray(plugins)) {
|
|
141
|
+
const r = [];
|
|
142
|
+
const vals = value.slice(1);
|
|
143
|
+
for (let i = 0; i < vals.length; i++) {
|
|
144
|
+
const v = vals[i];
|
|
145
|
+
stack.push([v, (v) => {
|
|
146
|
+
r[i] = v;
|
|
147
|
+
}]);
|
|
148
|
+
}
|
|
149
|
+
postRun.push(() => {
|
|
150
|
+
for (const plugin of plugins) {
|
|
151
|
+
const result = plugin(value[0], ...r);
|
|
152
|
+
if (result) {
|
|
153
|
+
set(hydrated[index] = result.value);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw new SyntaxError();
|
|
158
|
+
});
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
throw new SyntaxError();
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
const array = [];
|
|
165
|
+
hydrated[index] = array;
|
|
166
|
+
for (let i = 0; i < value.length; i++) {
|
|
167
|
+
const n = value[i];
|
|
168
|
+
if (n !== -1) stack.push([n, (v) => {
|
|
169
|
+
array[i] = v;
|
|
170
|
+
}]);
|
|
171
|
+
}
|
|
172
|
+
set(array);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const object = {};
|
|
177
|
+
hydrated[index] = object;
|
|
178
|
+
for (const key of Object.keys(value).reverse()) {
|
|
179
|
+
const r = [];
|
|
180
|
+
stack.push([value[key], (v) => {
|
|
181
|
+
r[1] = v;
|
|
182
|
+
}]);
|
|
183
|
+
stack.push([Number(key.slice(1)), (k) => {
|
|
184
|
+
r[0] = k;
|
|
185
|
+
}]);
|
|
186
|
+
postRun.push(() => {
|
|
187
|
+
object[r[0]] = r[1];
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
set(object);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
while (postRun.length > 0) postRun.pop()();
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { unflatten };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#region vendor/turbo-stream-v2/utils.ts
|
|
12
|
+
const SUPPORTED_ERROR_TYPES = [
|
|
13
|
+
"EvalError",
|
|
14
|
+
"RangeError",
|
|
15
|
+
"ReferenceError",
|
|
16
|
+
"SyntaxError",
|
|
17
|
+
"TypeError",
|
|
18
|
+
"URIError"
|
|
19
|
+
];
|
|
20
|
+
var Deferred = class {
|
|
21
|
+
promise;
|
|
22
|
+
resolve;
|
|
23
|
+
reject;
|
|
24
|
+
constructor() {
|
|
25
|
+
this.promise = new Promise((resolve, reject) => {
|
|
26
|
+
this.resolve = resolve;
|
|
27
|
+
this.reject = reject;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function createLineSplittingTransform() {
|
|
32
|
+
const decoder = new TextDecoder();
|
|
33
|
+
let leftover = "";
|
|
34
|
+
return new TransformStream({
|
|
35
|
+
transform(chunk, controller) {
|
|
36
|
+
const str = decoder.decode(chunk, { stream: true });
|
|
37
|
+
const parts = (leftover + str).split("\n");
|
|
38
|
+
leftover = parts.pop() || "";
|
|
39
|
+
for (const part of parts) controller.enqueue(part);
|
|
40
|
+
},
|
|
41
|
+
flush(controller) {
|
|
42
|
+
if (leftover) controller.enqueue(leftover);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { Deferred, SUPPORTED_ERROR_TYPES, createLineSplittingTransform };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Backend For Frontend
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Backend For Frontend
|
|
6
|
+
|
|
7
|
+
[MODES: framework]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
While React Router can serve as your fullstack application, it also fits perfectly into the "Backend for Frontend" architecture.
|
|
13
|
+
|
|
14
|
+
The BFF strategy employs a web server with a job scoped to serving the frontend web app and connecting it to the services it needs: your database, mailer, job queues, existing backend APIs (REST, GraphQL), etc. Instead of your UI integrating directly from the browser to these services, it connects to the BFF, and the BFF connects to your services.
|
|
15
|
+
|
|
16
|
+
Mature apps already have a lot of backend application code in Ruby, Elixir, PHP, etc., and there's no reason to justify migrating it all to a server-side JavaScript runtime just to get the benefits of React Router. Instead, you can use your React Router app as a backend for your frontend.
|
|
17
|
+
|
|
18
|
+
You can use `fetch` right from your loaders and actions to your backend.
|
|
19
|
+
|
|
20
|
+
```tsx lines=[7,13,17]
|
|
21
|
+
import escapeHtml from "escape-html";
|
|
22
|
+
|
|
23
|
+
export async function loader() {
|
|
24
|
+
const apiUrl = "https://api.example.com/some-data.json";
|
|
25
|
+
const res = await fetch(apiUrl, {
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${process.env.API_TOKEN}`,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const data = await res.json();
|
|
32
|
+
|
|
33
|
+
const prunedData = data.map((record) => {
|
|
34
|
+
return {
|
|
35
|
+
id: record.id,
|
|
36
|
+
title: record.title,
|
|
37
|
+
formattedBody: escapeHtml(record.content),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return { prunedData };
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
There are several benefits of this approach vs. fetching directly from the browser. The highlighted lines above show how you can:
|
|
45
|
+
|
|
46
|
+
1. Simplify third-party integrations and keep tokens and secrets out of client bundles
|
|
47
|
+
2. Prune the data down to send less kB over the network, speeding up your app significantly
|
|
48
|
+
3. Move a lot of code from browser bundles to the server, like `escapeHtml`, which speeds up your app. Additionally, moving code to the server usually makes your code easier to maintain since server-side code doesn't have to worry about UI states for async operations
|
|
49
|
+
|
|
50
|
+
Again, React Router can be used as your only server by talking directly to the database and other services with server-side JavaScript APIs, but it also works perfectly as a backend for your frontend. Go ahead and keep your existing API server for application logic and let React Router connect the UI to it.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Automatic Code Splitting
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Automatic Code Splitting
|
|
6
|
+
|
|
7
|
+
[MODES: framework]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
When using React Router's framework features, your application is automatically code split to improve the performance of initial load times when users visit your application.
|
|
13
|
+
|
|
14
|
+
## Code Splitting by Route
|
|
15
|
+
|
|
16
|
+
Consider this simple route config:
|
|
17
|
+
|
|
18
|
+
```tsx filename=app/routes.ts
|
|
19
|
+
import {
|
|
20
|
+
type RouteConfig,
|
|
21
|
+
route,
|
|
22
|
+
} from "@react-router/dev/routes";
|
|
23
|
+
|
|
24
|
+
export default [
|
|
25
|
+
route("/contact", "./contact.tsx"),
|
|
26
|
+
route("/about", "./about.tsx"),
|
|
27
|
+
] satisfies RouteConfig;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Instead of bundling all routes into a single giant build, the modules referenced (`contact.tsx` and `about.tsx`) become entry points to the bundler.
|
|
31
|
+
|
|
32
|
+
Because these entry points are coupled to URL segments, React Router knows just from a URL which bundles are needed in the browser, and more importantly, which are not.
|
|
33
|
+
|
|
34
|
+
If the user visits `"/about"` then the bundles for `about.tsx` will be loaded but not `contact.tsx`. This drastically reduces the JavaScript footprint for initial page loads and speeds up your application.
|
|
35
|
+
|
|
36
|
+
## Route Module Splitting
|
|
37
|
+
|
|
38
|
+
React Router can also split client-side route exports (`clientLoader`, `clientAction`, `clientMiddleware`, `HydrateFallback`) into separate chunks that can be loaded independently from the route component.
|
|
39
|
+
|
|
40
|
+
This allows these exports to be fetched and executed while the component code is still downloading, improving performance for client-side data loading.
|
|
41
|
+
|
|
42
|
+
This behavior is enabled by default. You can set `splitRouteModules` to `false` to opt out, or `"enforce"` to require all routes to be splittable. The `"enforce"` option will cause build failures for routes that cannot be split due to shared code.
|
|
43
|
+
|
|
44
|
+
```ts filename=react-router.config.ts
|
|
45
|
+
import type { Config } from "@react-router/dev/config";
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
splitRouteModules: false,
|
|
49
|
+
} satisfies Config;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Removal of Server Code
|
|
53
|
+
|
|
54
|
+
Any server-only [Route Module APIs][route-module] will be removed from the bundles. Consider this route module:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
export async function loader() {
|
|
58
|
+
return { message: "hello" };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function action() {
|
|
62
|
+
console.log(Date.now());
|
|
63
|
+
return { ok: true };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function headers() {
|
|
67
|
+
return { "Cache-Control": "max-age=300" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default function Component({ loaderData }) {
|
|
71
|
+
return <div>{loaderData.message}</div>;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
After building for the browser, only the `Component` will still be in the bundle, so you can use server-only code in the other module exports.
|
|
76
|
+
|
|
77
|
+
[route-module]: ../../start/framework/route-module
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Network Concurrency Management
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Network Concurrency Management
|
|
6
|
+
|
|
7
|
+
[MODES: framework, data]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
When building web applications, managing network requests can be a daunting task. The challenges of ensuring up-to-date data and handling simultaneous requests often lead to complex logic in the application to deal with interruptions and race conditions. React Router simplifies this process by automating network management while mirroring and expanding upon the intuitive behavior of web browsers.
|
|
13
|
+
|
|
14
|
+
To help understand how React Router handles concurrency, it's important to remember that after `form` submissions, React Router will fetch fresh data from the `loader`s. This is called revalidation.
|
|
15
|
+
|
|
16
|
+
## Natural Alignment with Browser Behavior
|
|
17
|
+
|
|
18
|
+
React Router's handling of network concurrency is heavily inspired by the default behavior of web browsers when processing documents.
|
|
19
|
+
|
|
20
|
+
### Link Navigation
|
|
21
|
+
|
|
22
|
+
**Browser Behavior**: When you click on a link in a browser and then click on another before the page transition completes, the browser prioritizes the most recent `action`. It cancels the initial request, focusing solely on the latest link clicked.
|
|
23
|
+
|
|
24
|
+
**React Router Behavior**: React Router manages client-side navigation the same way. When a link is clicked within a React Router application, it initiates fetch requests for each `loader` tied to the target URL. If another navigation interrupts the initial navigation, React Router cancels the previous fetch requests, ensuring that only the latest requests proceed.
|
|
25
|
+
|
|
26
|
+
### Form Submission
|
|
27
|
+
|
|
28
|
+
**Browser Behavior**: If you initiate a form submission in a browser and then quickly submit another form again, the browser disregards the first submission, processing only the latest one.
|
|
29
|
+
|
|
30
|
+
**React Router Behavior**: React Router mimics this behavior when working with forms. If a form is submitted and another submission occurs before the first completes, React Router cancels the original fetch requests. It then waits for the latest submission to complete before triggering page revalidation again.
|
|
31
|
+
|
|
32
|
+
## Concurrent Submissions and Revalidation
|
|
33
|
+
|
|
34
|
+
While standard browsers are limited to one request at a time for navigations and form submissions, React Router elevates this behavior. Unlike navigation, with [`useFetcher`][use_fetcher] multiple requests can be in flight simultaneously.
|
|
35
|
+
|
|
36
|
+
React Router is designed to handle multiple form submissions to server `action`s and concurrent revalidation requests efficiently. It ensures that as soon as new data is available, the state is updated promptly. However, React Router also safeguards against potential pitfalls by refraining from committing stale data when other `action`s introduce race conditions.
|
|
37
|
+
|
|
38
|
+
For instance, if three form submissions are in progress, and one completes, React Router updates the UI with that data immediately without waiting for the other two so that the UI remains responsive and dynamic. As the remaining submissions finalize, React Router continues to update the UI, ensuring that the most recent data is displayed.
|
|
39
|
+
|
|
40
|
+
Using this key:
|
|
41
|
+
|
|
42
|
+
- `|`: Submission begins
|
|
43
|
+
- ✓: Action complete, data revalidation begins
|
|
44
|
+
- ✅: Revalidated data is committed to the UI
|
|
45
|
+
- ❌: Request cancelled
|
|
46
|
+
|
|
47
|
+
We can visualize this scenario in the following diagram:
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
submission 1: |----✓-----✅
|
|
51
|
+
submission 2: |-----✓-----✅
|
|
52
|
+
submission 3: |-----✓-----✅
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
However, if a subsequent submission's revalidation completes before an earlier one, React Router discards the earlier data, ensuring that only the most up-to-date information is reflected in the UI:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
submission 1: |----✓---------❌
|
|
59
|
+
submission 2: |-----✓-----✅
|
|
60
|
+
submission 3: |-----✓-----✅
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Because the revalidation from submission (2) started later and landed earlier than submission (1), the requests from submission (1) are canceled and only the data from submission (2) is committed to the UI. It was requested later, so it's more likely to contain the updated values from both (1) and (2).
|
|
64
|
+
|
|
65
|
+
## Potential for Stale Data
|
|
66
|
+
|
|
67
|
+
It's unlikely your users will ever experience this, but there are still chances for the user to see stale data in very rare conditions with inconsistent infrastructure. Even though React Router cancels requests for stale data, they will still end up making it to the server. Canceling a request in the browser simply releases browser resources for that request; it can't "catch up" and stop it from getting to the server. In extremely rare conditions, a canceled request may change data after the interrupting `action`'s revalidation lands. Consider this diagram:
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
👇 interruption with new submission
|
|
71
|
+
|----❌----------------------✓
|
|
72
|
+
|-------✓-----✅
|
|
73
|
+
👆
|
|
74
|
+
initial request reaches the server
|
|
75
|
+
after the interrupting submission
|
|
76
|
+
has completed revalidation
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The user is now looking at different data than what is on the server. Note that this problem is both extremely rare and exists with default browser behavior, too. The chance of the initial request reaching the server later than both the submission and revalidation of the second is unexpected on any network and server infrastructure. If this is a concern with your infrastructure, you can send timestamps with your form submissions and write server logic to ignore stale submissions.
|
|
80
|
+
|
|
81
|
+
## Example
|
|
82
|
+
|
|
83
|
+
In UI components like comboboxes, each keystroke can trigger a network request. Managing such rapid, consecutive requests can be tricky, especially when ensuring that the displayed results match the most recent query. However, with React Router, this challenge is automatically handled, ensuring that users see the correct results without developers having to micromanage the network.
|
|
84
|
+
|
|
85
|
+
```tsx filename=app/pages/city-search.tsx
|
|
86
|
+
export async function loader({ request }) {
|
|
87
|
+
const { searchParams } = new URL(request.url);
|
|
88
|
+
const cities = await searchCities(searchParams.get("q"));
|
|
89
|
+
return cities;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function CitySearchCombobox() {
|
|
93
|
+
const fetcher = useFetcher<typeof loader>();
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<fetcher.Form action="/city-search">
|
|
97
|
+
<Combobox aria-label="Cities">
|
|
98
|
+
<ComboboxInput
|
|
99
|
+
name="q"
|
|
100
|
+
onChange={(event) =>
|
|
101
|
+
// submit the form onChange to get the list of cities
|
|
102
|
+
fetcher.submit(event.target.form)
|
|
103
|
+
}
|
|
104
|
+
/>
|
|
105
|
+
|
|
106
|
+
{/* render with the loader's data */}
|
|
107
|
+
{fetcher.data ? (
|
|
108
|
+
<ComboboxPopover className="shadow-popup">
|
|
109
|
+
{fetcher.data.length > 0 ? (
|
|
110
|
+
<ComboboxList>
|
|
111
|
+
{fetcher.data.map((city) => (
|
|
112
|
+
<ComboboxOption
|
|
113
|
+
key={city.id}
|
|
114
|
+
value={city.name}
|
|
115
|
+
/>
|
|
116
|
+
))}
|
|
117
|
+
</ComboboxList>
|
|
118
|
+
) : (
|
|
119
|
+
<span>No results found</span>
|
|
120
|
+
)}
|
|
121
|
+
</ComboboxPopover>
|
|
122
|
+
) : null}
|
|
123
|
+
</Combobox>
|
|
124
|
+
</fetcher.Form>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
All the application needs to know is how to query the data and how to render it. React Router handles the network.
|
|
130
|
+
|
|
131
|
+
## Conclusion
|
|
132
|
+
|
|
133
|
+
React Router offers developers an intuitive, browser-based approach to managing network requests. By mirroring browser behaviors and enhancing them where needed, it simplifies the complexities of concurrency, revalidation, and potential race conditions. Whether you're building a simple webpage or a sophisticated web application, React Router ensures that your user interactions are smooth, reliable, and always up to date.
|
|
134
|
+
|
|
135
|
+
[use_fetcher]: ../api/hooks/useFetcher
|