react-router 7.15.1 → 8.3.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 +181 -2
- 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 +1789 -1657
- package/dist/development/index-react-server.js +3074 -3674
- package/dist/development/index.d.ts +41 -1469
- package/dist/development/index.js +36 -2621
- package/dist/development/lib/actions.js +50 -0
- package/dist/development/lib/components.d.ts +1030 -0
- package/dist/development/lib/components.js +841 -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 +2054 -0
- package/dist/development/lib/dom/lib.js +1272 -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 +198 -0
- package/dist/development/lib/dom/ssr/components.js +589 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/development/lib/dom/ssr/fallback.js +33 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +185 -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 +75 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +121 -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 +48 -0
- package/dist/development/lib/dom/ssr/server.js +69 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +345 -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 +150 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +974 -0
- package/dist/development/lib/hooks.js +1415 -0
- package/dist/development/lib/href.d.ts +36 -0
- package/dist/development/lib/href.js +70 -0
- package/dist/development/lib/router/history.d.ts +264 -0
- package/dist/development/lib/router/history.js +378 -0
- package/dist/development/lib/router/instrumentation.d.ts +111 -0
- package/dist/development/lib/router/instrumentation.js +290 -0
- package/dist/development/lib/router/links.d.ts +114 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2988 -0
- package/dist/development/lib/router/url.js +18 -0
- package/dist/development/lib/router/utils.d.ts +960 -0
- package/dist/development/lib/router/utils.js +881 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +612 -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 +97 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +224 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +152 -0
- package/dist/development/lib/rsc/server.ssr.js +419 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +92 -0
- package/dist/development/lib/server-runtime/cookies.js +153 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -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 +75 -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 +22 -0
- package/dist/development/lib/server-runtime/server.js +364 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +53 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +58 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +174 -0
- package/dist/development/lib/server-runtime/sessions.js +115 -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 +28 -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-Bsscfj79.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 +179 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +39 -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 +1789 -1657
- package/dist/production/index-react-server.js +3065 -3674
- package/dist/production/index.d.ts +41 -1469
- package/dist/production/index.js +36 -2621
- package/dist/production/lib/actions.js +50 -0
- package/dist/production/lib/components.d.ts +1030 -0
- package/dist/production/lib/components.js +841 -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 +2054 -0
- package/dist/production/lib/dom/lib.js +1272 -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 +198 -0
- package/dist/production/lib/dom/ssr/components.js +589 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/production/lib/dom/ssr/fallback.js +23 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +185 -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 +75 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +121 -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 +48 -0
- package/dist/production/lib/dom/ssr/server.js +69 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +345 -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 +150 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +974 -0
- package/dist/production/lib/hooks.js +1400 -0
- package/dist/production/lib/href.d.ts +36 -0
- package/dist/production/lib/href.js +70 -0
- package/dist/production/lib/router/history.d.ts +264 -0
- package/dist/production/lib/router/history.js +378 -0
- package/dist/production/lib/router/instrumentation.d.ts +111 -0
- package/dist/production/lib/router/instrumentation.js +290 -0
- package/dist/production/lib/router/links.d.ts +114 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2988 -0
- package/dist/production/lib/router/url.js +18 -0
- package/dist/production/lib/router/utils.d.ts +960 -0
- package/dist/production/lib/router/utils.js +872 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +612 -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 +97 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +224 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +152 -0
- package/dist/production/lib/rsc/server.ssr.js +419 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +92 -0
- package/dist/production/lib/server-runtime/cookies.js +153 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -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 +75 -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 +22 -0
- package/dist/production/lib/server-runtime/server.js +364 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +53 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +58 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +174 -0
- package/dist/production/lib/server-runtime/sessions.js +115 -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 +28 -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-Bsscfj79.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 +179 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +39 -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 +142 -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 +165 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +661 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +647 -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 +951 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +85 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +39 -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 +36 -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 +56 -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 +268 -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 +174 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +104 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +41 -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 +200 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +111 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/router-provider.md +445 -0
- package/docs/upgrading/v7.md +460 -0
- package/package.json +44 -87
- package/dist/development/browser-3AnU12UI.d.mts +0 -318
- package/dist/development/browser-BOdXz9dK.d.ts +0 -318
- package/dist/development/chunk-4N6VE7H7.mjs +0 -11528
- package/dist/development/chunk-4YRVXM2U.js +0 -188
- package/dist/development/chunk-66UKHEGQ.js +0 -1362
- package/dist/development/chunk-D6LUOGOQ.js +0 -10229
- package/dist/development/chunk-RJYABSBD.mjs +0 -2585
- package/dist/development/context-ByvtofY2.d.mts +0 -1771
- package/dist/development/data-BVUf681J.d.mts +0 -1732
- package/dist/development/data-BqZ2x964.d.ts +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-BS5F89FR.d.ts +0 -3655
- package/dist/development/index-react-server-client-DY04-103.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 -1472
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-cRWWLfsU.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-Df8okEea.d.mts +0 -30
- package/dist/production/browser-3AnU12UI.d.mts +0 -318
- package/dist/production/browser-BOdXz9dK.d.ts +0 -318
- package/dist/production/chunk-6S4627ZB.mjs +0 -2585
- package/dist/production/chunk-HUBUW7R3.js +0 -10229
- package/dist/production/chunk-JAKZPQZC.mjs +0 -11528
- package/dist/production/chunk-PNZCCTKT.js +0 -1362
- package/dist/production/chunk-Y6IFXO7V.js +0 -188
- package/dist/production/context-ByvtofY2.d.mts +0 -1771
- package/dist/production/data-BVUf681J.d.mts +0 -1732
- package/dist/production/data-BqZ2x964.d.ts +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-BS5F89FR.d.ts +0 -3655
- package/dist/production/index-react-server-client-DY04-103.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 -1472
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-cRWWLfsU.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-Df8okEea.d.mts +0 -30
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.3.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 { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
|
|
12
|
+
import { createBrowserHistory, createPath, invariant } from "../router/history.js";
|
|
13
|
+
import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
|
|
14
|
+
import { createRouter, hasInvalidProtocol, isMutationMethod } from "../router/router.js";
|
|
15
|
+
import { RSCRouterContext } from "../context.js";
|
|
16
|
+
import { RouterProvider } from "../components.js";
|
|
17
|
+
import { createRequestInit } from "../dom/ssr/data.js";
|
|
18
|
+
import { getSingleFetchDataStrategyImpl, singleFetchUrl, stripIndexParam } from "../dom/ssr/single-fetch.js";
|
|
19
|
+
import { noActionDefinedError, shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
|
|
20
|
+
import { getPathsWithAncestors, handleClientVersionMismatch } from "../dom/ssr/fog-of-war.js";
|
|
21
|
+
import { FrameworkContext, setIsHydrated } from "../dom/ssr/components.js";
|
|
22
|
+
import { RSCRouterGlobalErrorBoundary } from "./errorBoundaries.js";
|
|
23
|
+
import { populateRSCRouteModules } from "./route-modules.js";
|
|
24
|
+
import { getHydrationData } from "../dom/ssr/hydration.js";
|
|
25
|
+
import * as React$1 from "react";
|
|
26
|
+
import * as ReactDOM from "react-dom";
|
|
27
|
+
//#region lib/rsc/browser.tsx
|
|
28
|
+
const defaultManifestPath = "/__manifest";
|
|
29
|
+
/**
|
|
30
|
+
* Create a React `callServer` implementation for React Router.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import {
|
|
34
|
+
* createFromReadableStream,
|
|
35
|
+
* createTemporaryReferenceSet,
|
|
36
|
+
* encodeReply,
|
|
37
|
+
* setServerCallback,
|
|
38
|
+
* } from "@vitejs/plugin-rsc/browser";
|
|
39
|
+
* import { unstable_createCallServer as createCallServer } from "react-router";
|
|
40
|
+
*
|
|
41
|
+
* setServerCallback(
|
|
42
|
+
* createCallServer({
|
|
43
|
+
* createFromReadableStream,
|
|
44
|
+
* createTemporaryReferenceSet,
|
|
45
|
+
* encodeReply,
|
|
46
|
+
* })
|
|
47
|
+
* );
|
|
48
|
+
*
|
|
49
|
+
* @name unstable_createCallServer
|
|
50
|
+
* @public
|
|
51
|
+
* @category RSC
|
|
52
|
+
* @mode data
|
|
53
|
+
* @param opts Options
|
|
54
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
55
|
+
* `createFromReadableStream`. Used to decode payloads from the server.
|
|
56
|
+
* @param opts.createTemporaryReferenceSet A function that creates a temporary
|
|
57
|
+
* reference set for the [RSC](https://react.dev/reference/rsc/server-components)
|
|
58
|
+
* payload.
|
|
59
|
+
* @param opts.encodeReply Your `react-server-dom-xyz/client`'s `encodeReply`.
|
|
60
|
+
* Used when sending payloads to the server.
|
|
61
|
+
* @param opts.fetch Optional [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
62
|
+
* implementation. Defaults to global [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
|
|
63
|
+
* @returns A function that can be used to call server actions.
|
|
64
|
+
*/
|
|
65
|
+
function createCallServer({ createFromReadableStream, createTemporaryReferenceSet, encodeReply, fetch: fetchImplementation = fetch }) {
|
|
66
|
+
const globalVar = window;
|
|
67
|
+
let landedActionId = 0;
|
|
68
|
+
return async (id, args) => {
|
|
69
|
+
let actionId = globalVar.__routerActionID = (globalVar.__routerActionID ??= 0) + 1;
|
|
70
|
+
const temporaryReferences = createTemporaryReferenceSet();
|
|
71
|
+
const payloadPromise = fetchImplementation(new Request(location.href, {
|
|
72
|
+
body: await encodeReply(args, { temporaryReferences }),
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
Accept: "text/x-component",
|
|
76
|
+
"rsc-action-id": id
|
|
77
|
+
}
|
|
78
|
+
})).then((response) => {
|
|
79
|
+
if (!response.body) throw new Error("No response body");
|
|
80
|
+
return createFromReadableStream(response.body, { temporaryReferences });
|
|
81
|
+
});
|
|
82
|
+
React$1.startTransition(() => Promise.resolve(payloadPromise).then(async (payload) => {
|
|
83
|
+
if (payload.type === "redirect") {
|
|
84
|
+
let location = normalizeRedirectLocation(payload.location);
|
|
85
|
+
if (payload.reload || isExternalLocation(location)) {
|
|
86
|
+
if (hasInvalidProtocol(location)) throw new Error("Invalid redirect location");
|
|
87
|
+
window.location.href = location;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
React$1.startTransition(() => {
|
|
91
|
+
globalVar.__reactRouterDataRouter.navigate(location, { replace: payload.replace });
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (payload.type !== "action") throw new Error("Unexpected payload type");
|
|
96
|
+
const rerender = await payload.rerender;
|
|
97
|
+
if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
|
|
98
|
+
if (rerender.type === "redirect") {
|
|
99
|
+
let location = normalizeRedirectLocation(rerender.location);
|
|
100
|
+
if (rerender.reload || isExternalLocation(location)) {
|
|
101
|
+
if (hasInvalidProtocol(location)) throw new Error("Invalid redirect location");
|
|
102
|
+
window.location.href = location;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
React$1.startTransition(() => {
|
|
106
|
+
globalVar.__reactRouterDataRouter.navigate(location, { replace: rerender.replace });
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
React$1.startTransition(() => {
|
|
111
|
+
let lastMatch;
|
|
112
|
+
for (const match of rerender.matches) {
|
|
113
|
+
globalVar.__reactRouterDataRouter.patchRoutes(lastMatch?.id ?? null, [createRouteFromServerManifest(match)], true);
|
|
114
|
+
lastMatch = match;
|
|
115
|
+
}
|
|
116
|
+
window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp({
|
|
117
|
+
loaderData: Object.assign({}, globalVar.__reactRouterDataRouter.state.loaderData, rerender.loaderData),
|
|
118
|
+
errors: rerender.errors ? Object.assign({}, globalVar.__reactRouterDataRouter.state.errors, rerender.errors) : null
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}).catch(() => {}));
|
|
123
|
+
return payloadPromise.then((payload) => {
|
|
124
|
+
if (payload.type !== "action" && payload.type !== "redirect") throw new Error("Unexpected payload type");
|
|
125
|
+
return payload.actionResult;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function createRouterFromPayload({ fetchImplementation, createFromReadableStream, getContext, payload }) {
|
|
130
|
+
const globalVar = window;
|
|
131
|
+
if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules) return {
|
|
132
|
+
router: globalVar.__reactRouterDataRouter,
|
|
133
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
134
|
+
};
|
|
135
|
+
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
136
|
+
let { clientVersion } = payload;
|
|
137
|
+
globalVar.__reactRouterRouteModules = globalVar.__reactRouterRouteModules ?? {};
|
|
138
|
+
populateRSCRouteModules(globalVar.__reactRouterRouteModules, payload.matches);
|
|
139
|
+
let routes = payload.matches.reduceRight((previous, match) => {
|
|
140
|
+
const route = createRouteFromServerManifest(match, payload);
|
|
141
|
+
if (previous.length > 0) route.children = previous;
|
|
142
|
+
else if (!route.index) route.children = [];
|
|
143
|
+
return [route];
|
|
144
|
+
}, []);
|
|
145
|
+
let applyPatchesPromise;
|
|
146
|
+
globalVar.__reactRouterDataRouter = createRouter({
|
|
147
|
+
routes,
|
|
148
|
+
getContext,
|
|
149
|
+
basename: payload.basename,
|
|
150
|
+
history: createBrowserHistory(),
|
|
151
|
+
hydrationData: getHydrationData({
|
|
152
|
+
state: {
|
|
153
|
+
loaderData: payload.loaderData,
|
|
154
|
+
actionData: payload.actionData,
|
|
155
|
+
errors: payload.errors
|
|
156
|
+
},
|
|
157
|
+
routes,
|
|
158
|
+
getRouteInfo: (routeId) => {
|
|
159
|
+
let match = payload.matches.find((m) => m.id === routeId);
|
|
160
|
+
invariant(match, "Route not found in payload");
|
|
161
|
+
return {
|
|
162
|
+
clientLoader: match.clientLoader,
|
|
163
|
+
hasLoader: match.hasLoader,
|
|
164
|
+
hasHydrateFallback: match.hydrateFallbackElement != null
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
location: payload.location,
|
|
168
|
+
basename: payload.basename,
|
|
169
|
+
isSpaMode: false
|
|
170
|
+
}),
|
|
171
|
+
async patchRoutesOnNavigation({ path, signal, fetcherKey }) {
|
|
172
|
+
if (payload.routeDiscovery.mode === "initial") {
|
|
173
|
+
if (!applyPatchesPromise) applyPatchesPromise = (async () => {
|
|
174
|
+
if (!payload.patches) return;
|
|
175
|
+
let patches = await payload.patches;
|
|
176
|
+
React$1.startTransition(() => {
|
|
177
|
+
patches.forEach((p) => {
|
|
178
|
+
window.__reactRouterDataRouter.patchRoutes(p.parentId ?? null, [createRouteFromServerManifest(p)]);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
})();
|
|
182
|
+
await applyPatchesPromise;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (discoveredPaths.has(path)) return;
|
|
186
|
+
let { state } = globalVar.__reactRouterDataRouter;
|
|
187
|
+
await fetchAndApplyManifestPatches([path], createFromReadableStream, fetchImplementation, clientVersion, fetcherKey ? window.location.href : createPath(state.navigation.location || state.location), signal);
|
|
188
|
+
},
|
|
189
|
+
dataStrategy: getRSCSingleFetchDataStrategy(() => globalVar.__reactRouterDataRouter, true, createFromReadableStream, fetchImplementation, clientVersion)
|
|
190
|
+
});
|
|
191
|
+
if (globalVar.__reactRouterDataRouter.state.initialized) {
|
|
192
|
+
globalVar.__routerInitialized = true;
|
|
193
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
194
|
+
} else globalVar.__routerInitialized = false;
|
|
195
|
+
let lastLoaderData = void 0;
|
|
196
|
+
globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
|
|
197
|
+
if (lastLoaderData !== loaderData) globalVar.__routerActionID = (globalVar.__routerActionID ??= 0) + 1;
|
|
198
|
+
});
|
|
199
|
+
globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
|
|
200
|
+
const oldRoutes = window.__reactRouterDataRouter.routes;
|
|
201
|
+
const newRoutes = [];
|
|
202
|
+
function walkRoutes(routes, parentId) {
|
|
203
|
+
return routes.map((route) => {
|
|
204
|
+
const routeUpdate = routeUpdateByRouteId.get(route.id);
|
|
205
|
+
if (routeUpdate) {
|
|
206
|
+
const { routeModule, hasAction, hasComponent, hasLoader } = routeUpdate;
|
|
207
|
+
const newRoute = createRouteFromServerManifest({
|
|
208
|
+
clientAction: routeModule.clientAction,
|
|
209
|
+
clientLoader: routeModule.clientLoader,
|
|
210
|
+
element: route.element,
|
|
211
|
+
errorElement: route.errorElement,
|
|
212
|
+
handle: route.handle,
|
|
213
|
+
hasAction,
|
|
214
|
+
hasComponent,
|
|
215
|
+
hasLoader,
|
|
216
|
+
hydrateFallbackElement: route.hydrateFallbackElement,
|
|
217
|
+
id: route.id,
|
|
218
|
+
index: route.index,
|
|
219
|
+
links: routeModule.links,
|
|
220
|
+
meta: routeModule.meta,
|
|
221
|
+
parentId,
|
|
222
|
+
path: route.path,
|
|
223
|
+
shouldRevalidate: routeModule.shouldRevalidate
|
|
224
|
+
});
|
|
225
|
+
if (route.children) newRoute.children = walkRoutes(route.children, route.id);
|
|
226
|
+
return newRoute;
|
|
227
|
+
}
|
|
228
|
+
const updatedRoute = { ...route };
|
|
229
|
+
if (route.children) updatedRoute.children = walkRoutes(route.children, route.id);
|
|
230
|
+
return updatedRoute;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
newRoutes.push(...walkRoutes(oldRoutes, void 0));
|
|
234
|
+
window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
router: globalVar.__reactRouterDataRouter,
|
|
238
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const renderedRoutesContext = createContext();
|
|
242
|
+
function getRSCSingleFetchDataStrategy(getRouter, ssr, createFromReadableStream, fetchImplementation, clientVersion) {
|
|
243
|
+
let dataStrategy = getSingleFetchDataStrategyImpl(getRouter, (match) => {
|
|
244
|
+
let M = match;
|
|
245
|
+
return {
|
|
246
|
+
hasLoader: M.route.hasLoader,
|
|
247
|
+
hasClientLoader: M.route.hasClientLoader
|
|
248
|
+
};
|
|
249
|
+
}, getFetchAndDecodeViaRSC(getRouter, createFromReadableStream, fetchImplementation, clientVersion), ssr, (match) => {
|
|
250
|
+
let M = match;
|
|
251
|
+
return !M.route.hasComponent || M.route.element != null;
|
|
252
|
+
});
|
|
253
|
+
return async (args) => args.runClientMiddleware(async () => {
|
|
254
|
+
args.context.set(renderedRoutesContext, []);
|
|
255
|
+
let results = await dataStrategy(args);
|
|
256
|
+
const renderedRoutesById = /* @__PURE__ */ new Map();
|
|
257
|
+
for (const route of args.context.get(renderedRoutesContext)) {
|
|
258
|
+
if (!renderedRoutesById.has(route.id)) renderedRoutesById.set(route.id, []);
|
|
259
|
+
renderedRoutesById.get(route.id).push(route);
|
|
260
|
+
}
|
|
261
|
+
React$1.startTransition(() => {
|
|
262
|
+
for (const match of args.matches) {
|
|
263
|
+
const renderedRoutes = renderedRoutesById.get(match.route.id);
|
|
264
|
+
if (renderedRoutes) for (const rendered of renderedRoutes) window.__reactRouterDataRouter.patchRoutes(rendered.parentId ?? null, [createRouteFromServerManifest(rendered)], true);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return results;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function getFetchAndDecodeViaRSC(getRouter, createFromReadableStream, fetchImplementation, clientVersion) {
|
|
271
|
+
return async (args, targetRoutes) => {
|
|
272
|
+
let { request, context } = args;
|
|
273
|
+
let url = singleFetchUrl(request.url, "rsc");
|
|
274
|
+
if (request.method === "GET") {
|
|
275
|
+
url = stripIndexParam(url);
|
|
276
|
+
if (targetRoutes) url.searchParams.set("_routes", targetRoutes.join(","));
|
|
277
|
+
}
|
|
278
|
+
let res = await fetchImplementation(new Request(url, await createRequestInit(request)));
|
|
279
|
+
if (res.status >= 400 && !res.headers.has("X-Remix-Response")) throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
|
|
280
|
+
invariant(res.body, "No response body to decode");
|
|
281
|
+
try {
|
|
282
|
+
const payload = await createFromReadableStream(res.body, { temporaryReferences: void 0 });
|
|
283
|
+
if (payload.type === "redirect") return {
|
|
284
|
+
status: res.status,
|
|
285
|
+
data: { redirect: {
|
|
286
|
+
redirect: payload.location,
|
|
287
|
+
reload: payload.reload,
|
|
288
|
+
replace: payload.replace,
|
|
289
|
+
revalidate: false,
|
|
290
|
+
status: payload.status
|
|
291
|
+
} }
|
|
292
|
+
};
|
|
293
|
+
if (payload.type !== "render") throw new Error("Unexpected payload type");
|
|
294
|
+
if (clientVersion !== void 0 && await handleClientVersionMismatch(payload.clientVersion !== clientVersion, clientVersion, createPath(getRouter().state.navigation.location || getRouter().state.location))) return new Promise(() => {});
|
|
295
|
+
context.get(renderedRoutesContext).push(...payload.matches);
|
|
296
|
+
let results = { routes: {} };
|
|
297
|
+
const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
|
|
298
|
+
for (let [routeId, data] of Object.entries(payload[dataKey] || {})) results.routes[routeId] = { data };
|
|
299
|
+
if (payload.errors) for (let [routeId, error] of Object.entries(payload.errors)) results.routes[routeId] = { error };
|
|
300
|
+
return {
|
|
301
|
+
status: res.status,
|
|
302
|
+
data: results
|
|
303
|
+
};
|
|
304
|
+
} catch (cause) {
|
|
305
|
+
throw new Error("Unable to decode RSC response", { cause });
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Hydrates a server rendered {@link unstable_RSCPayload} in the browser.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* import { startTransition, StrictMode } from "react";
|
|
314
|
+
* import { hydrateRoot } from "react-dom/client";
|
|
315
|
+
* import {
|
|
316
|
+
* unstable_getRSCStream as getRSCStream,
|
|
317
|
+
* unstable_RSCHydratedRouter as RSCHydratedRouter,
|
|
318
|
+
* } from "react-router";
|
|
319
|
+
* import type { unstable_RSCPayload as RSCPayload } from "react-router";
|
|
320
|
+
*
|
|
321
|
+
* createFromReadableStream(getRSCStream()).then((payload) =>
|
|
322
|
+
* startTransition(async () => {
|
|
323
|
+
* hydrateRoot(
|
|
324
|
+
* document,
|
|
325
|
+
* <StrictMode>
|
|
326
|
+
* <RSCHydratedRouter
|
|
327
|
+
* createFromReadableStream={createFromReadableStream}
|
|
328
|
+
* payload={payload}
|
|
329
|
+
* />
|
|
330
|
+
* </StrictMode>,
|
|
331
|
+
* { formState: await getFormState(payload) },
|
|
332
|
+
* );
|
|
333
|
+
* }),
|
|
334
|
+
* );
|
|
335
|
+
*
|
|
336
|
+
* @name unstable_RSCHydratedRouter
|
|
337
|
+
* @public
|
|
338
|
+
* @category RSC
|
|
339
|
+
* @mode data
|
|
340
|
+
* @param props Props
|
|
341
|
+
* @param {unstable_RSCHydratedRouterProps.createFromReadableStream} props.createFromReadableStream n/a
|
|
342
|
+
* @param {unstable_RSCHydratedRouterProps.fetch} props.fetch n/a
|
|
343
|
+
* @param {unstable_RSCHydratedRouterProps.getContext} props.getContext n/a
|
|
344
|
+
* @param {unstable_RSCHydratedRouterProps.payload} props.payload n/a
|
|
345
|
+
* @returns A hydrated {@link DataRouter} that can be used to navigate and
|
|
346
|
+
* render routes.
|
|
347
|
+
*/
|
|
348
|
+
function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementation = fetch, payload, getContext }) {
|
|
349
|
+
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
350
|
+
let { routeDiscovery, clientVersion } = payload;
|
|
351
|
+
let { router, routeModules } = React$1.useMemo(() => createRouterFromPayload({
|
|
352
|
+
payload,
|
|
353
|
+
fetchImplementation,
|
|
354
|
+
getContext,
|
|
355
|
+
createFromReadableStream
|
|
356
|
+
}), [
|
|
357
|
+
createFromReadableStream,
|
|
358
|
+
payload,
|
|
359
|
+
fetchImplementation,
|
|
360
|
+
getContext
|
|
361
|
+
]);
|
|
362
|
+
React$1.useEffect(() => {
|
|
363
|
+
setIsHydrated();
|
|
364
|
+
}, []);
|
|
365
|
+
React$1.useLayoutEffect(() => {
|
|
366
|
+
const globalVar = window;
|
|
367
|
+
if (!globalVar.__routerInitialized) {
|
|
368
|
+
globalVar.__routerInitialized = true;
|
|
369
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
370
|
+
}
|
|
371
|
+
}, []);
|
|
372
|
+
let [{ routes, state }, setState] = React$1.useState(() => ({
|
|
373
|
+
routes: cloneRoutes(router.routes),
|
|
374
|
+
state: router.state
|
|
375
|
+
}));
|
|
376
|
+
React$1.useLayoutEffect(() => router.subscribe((newState) => {
|
|
377
|
+
if (diffRoutes(router.routes, routes)) React$1.startTransition(() => {
|
|
378
|
+
setState({
|
|
379
|
+
routes: cloneRoutes(router.routes),
|
|
380
|
+
state: newState
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
}), [
|
|
384
|
+
router.subscribe,
|
|
385
|
+
routes,
|
|
386
|
+
router
|
|
387
|
+
]);
|
|
388
|
+
const transitionEnabledRouter = React$1.useMemo(() => ({
|
|
389
|
+
...router,
|
|
390
|
+
state,
|
|
391
|
+
routes
|
|
392
|
+
}), [
|
|
393
|
+
router,
|
|
394
|
+
routes,
|
|
395
|
+
state
|
|
396
|
+
]);
|
|
397
|
+
React$1.useEffect(() => {
|
|
398
|
+
if (routeDiscovery.mode === "initial" || window.navigator?.connection?.saveData === true) return;
|
|
399
|
+
function registerElement(el) {
|
|
400
|
+
let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
|
401
|
+
if (!path) return;
|
|
402
|
+
let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
|
403
|
+
if (!discoveredPaths.has(pathname)) nextPaths.add(pathname);
|
|
404
|
+
}
|
|
405
|
+
async function fetchPatches() {
|
|
406
|
+
document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
|
407
|
+
let paths = Array.from(nextPaths.keys()).filter((path) => {
|
|
408
|
+
if (discoveredPaths.has(path)) {
|
|
409
|
+
nextPaths.delete(path);
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
return true;
|
|
413
|
+
});
|
|
414
|
+
if (paths.length === 0) return;
|
|
415
|
+
try {
|
|
416
|
+
await fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, clientVersion, null);
|
|
417
|
+
} catch (e) {
|
|
418
|
+
console.error("Failed to fetch manifest patches", e);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
let debouncedFetchPatches = debounce(fetchPatches, 100);
|
|
422
|
+
fetchPatches();
|
|
423
|
+
new MutationObserver(() => debouncedFetchPatches()).observe(document.documentElement, {
|
|
424
|
+
subtree: true,
|
|
425
|
+
childList: true,
|
|
426
|
+
attributes: true,
|
|
427
|
+
attributeFilter: [
|
|
428
|
+
"data-discover",
|
|
429
|
+
"href",
|
|
430
|
+
"action"
|
|
431
|
+
]
|
|
432
|
+
});
|
|
433
|
+
}, [
|
|
434
|
+
routeDiscovery,
|
|
435
|
+
createFromReadableStream,
|
|
436
|
+
fetchImplementation,
|
|
437
|
+
clientVersion
|
|
438
|
+
]);
|
|
439
|
+
const frameworkContext = {
|
|
440
|
+
future: {},
|
|
441
|
+
isSpaMode: false,
|
|
442
|
+
ssr: true,
|
|
443
|
+
criticalCss: "",
|
|
444
|
+
manifest: {
|
|
445
|
+
routes: {},
|
|
446
|
+
version: "1",
|
|
447
|
+
url: "",
|
|
448
|
+
entry: {
|
|
449
|
+
module: "",
|
|
450
|
+
imports: []
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
routeDiscovery: payload.routeDiscovery.mode === "initial" ? {
|
|
454
|
+
mode: "initial",
|
|
455
|
+
manifestPath: defaultManifestPath
|
|
456
|
+
} : {
|
|
457
|
+
mode: "lazy",
|
|
458
|
+
manifestPath: payload.routeDiscovery.manifestPath || defaultManifestPath
|
|
459
|
+
},
|
|
460
|
+
routeModules
|
|
461
|
+
};
|
|
462
|
+
return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: state.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(RouterProvider, {
|
|
463
|
+
router: transitionEnabledRouter,
|
|
464
|
+
flushSync: ReactDOM.flushSync
|
|
465
|
+
}))));
|
|
466
|
+
}
|
|
467
|
+
function createRouteFromServerManifest(match, payload) {
|
|
468
|
+
let hasInitialData = payload && match.id in payload.loaderData;
|
|
469
|
+
let initialData = payload?.loaderData[match.id];
|
|
470
|
+
let hasInitialError = payload?.errors && match.id in payload.errors;
|
|
471
|
+
let initialError = payload?.errors?.[match.id];
|
|
472
|
+
let isHydrationRequest = match.clientLoader?.hydrate === true || !match.hasLoader || match.hasComponent && !match.element;
|
|
473
|
+
invariant(window.__reactRouterRouteModules);
|
|
474
|
+
populateRSCRouteModules(window.__reactRouterRouteModules, match);
|
|
475
|
+
let dataRoute = {
|
|
476
|
+
id: match.id,
|
|
477
|
+
element: match.element,
|
|
478
|
+
errorElement: match.errorElement,
|
|
479
|
+
handle: match.handle,
|
|
480
|
+
hydrateFallbackElement: match.hydrateFallbackElement,
|
|
481
|
+
index: match.index,
|
|
482
|
+
loader: match.clientLoader ? async (args, singleFetch) => {
|
|
483
|
+
let _isHydrationRequest = isHydrationRequest;
|
|
484
|
+
isHydrationRequest = false;
|
|
485
|
+
return await match.clientLoader({
|
|
486
|
+
...args,
|
|
487
|
+
serverLoader: () => {
|
|
488
|
+
preventInvalidServerHandlerCall("loader", match.id, match.hasLoader);
|
|
489
|
+
if (_isHydrationRequest) {
|
|
490
|
+
if (hasInitialData) return initialData;
|
|
491
|
+
if (hasInitialError) throw initialError;
|
|
492
|
+
}
|
|
493
|
+
return callSingleFetch(singleFetch);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
} : (_, singleFetch) => callSingleFetch(singleFetch),
|
|
497
|
+
action: match.clientAction ? (args, singleFetch) => match.clientAction({
|
|
498
|
+
...args,
|
|
499
|
+
serverAction: async () => {
|
|
500
|
+
preventInvalidServerHandlerCall("action", match.id, match.hasLoader);
|
|
501
|
+
return await callSingleFetch(singleFetch);
|
|
502
|
+
}
|
|
503
|
+
}) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
|
|
504
|
+
throw noActionDefinedError("action", match.id);
|
|
505
|
+
},
|
|
506
|
+
path: match.path,
|
|
507
|
+
shouldRevalidate: match.shouldRevalidate,
|
|
508
|
+
hasLoader: true,
|
|
509
|
+
hasClientLoader: match.clientLoader != null,
|
|
510
|
+
hasComponent: match.hasComponent,
|
|
511
|
+
hasAction: match.hasAction,
|
|
512
|
+
hasClientAction: match.clientAction != null
|
|
513
|
+
};
|
|
514
|
+
if (typeof dataRoute.loader === "function") dataRoute.loader.hydrate = shouldHydrateRouteLoader(match.id, match.clientLoader, match.hasLoader, false);
|
|
515
|
+
return dataRoute;
|
|
516
|
+
}
|
|
517
|
+
function callSingleFetch(singleFetch) {
|
|
518
|
+
invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
|
|
519
|
+
return singleFetch();
|
|
520
|
+
}
|
|
521
|
+
function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
|
|
522
|
+
if (!hasHandler) {
|
|
523
|
+
let msg = `You are trying to call ${type === "action" ? "serverAction()" : "serverLoader()"} on a route that does not have a server ${type} (routeId: "${routeId}")`;
|
|
524
|
+
console.error(msg);
|
|
525
|
+
throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const nextPaths = /* @__PURE__ */ new Set();
|
|
529
|
+
const discoveredPathsMaxSize = 1e3;
|
|
530
|
+
const discoveredPaths = /* @__PURE__ */ new Set();
|
|
531
|
+
function getManifestUrl(paths, clientVersion) {
|
|
532
|
+
if (paths.length === 0) return null;
|
|
533
|
+
let url;
|
|
534
|
+
if (paths.length === 1) url = new URL(`${paths[0]}.manifest`, window.location.origin);
|
|
535
|
+
else {
|
|
536
|
+
let basename = (window.__reactRouterDataRouter.basename ?? "").replace(/^\/|\/$/g, "");
|
|
537
|
+
url = new URL(`${basename}/.manifest`, window.location.origin);
|
|
538
|
+
url.searchParams.set("paths", paths.sort().join(","));
|
|
539
|
+
}
|
|
540
|
+
if (clientVersion !== void 0) url.searchParams.set("version", clientVersion);
|
|
541
|
+
return url;
|
|
542
|
+
}
|
|
543
|
+
async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, clientVersion, errorReloadPath, signal) {
|
|
544
|
+
paths = getPathsWithAncestors(paths);
|
|
545
|
+
let url = getManifestUrl(paths, clientVersion);
|
|
546
|
+
if (url == null) return;
|
|
547
|
+
if (url.toString().length > 7680) {
|
|
548
|
+
nextPaths.clear();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
let response = await fetchImplementation(new Request(url, { signal }));
|
|
552
|
+
if (clientVersion !== void 0 && response.status === 204 && response.headers.has("X-Remix-Reload-Document")) {
|
|
553
|
+
await handleClientVersionMismatch(true, clientVersion, errorReloadPath);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (!response.body || response.status < 200 || response.status >= 300) throw new Error("Unable to fetch new route matches from the server");
|
|
557
|
+
let payload = await createFromReadableStream(response.body, { temporaryReferences: void 0 });
|
|
558
|
+
if (payload.type !== "manifest") throw new Error("Failed to patch routes");
|
|
559
|
+
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
560
|
+
let patches = await payload.patches;
|
|
561
|
+
React$1.startTransition(() => {
|
|
562
|
+
patches.forEach((p) => {
|
|
563
|
+
window.__reactRouterDataRouter.patchRoutes(p.parentId ?? null, [createRouteFromServerManifest(p)]);
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
function addToFifoQueue(path, queue) {
|
|
568
|
+
if (queue.size >= discoveredPathsMaxSize) {
|
|
569
|
+
let first = queue.values().next().value;
|
|
570
|
+
if (typeof first === "string") queue.delete(first);
|
|
571
|
+
}
|
|
572
|
+
queue.add(path);
|
|
573
|
+
}
|
|
574
|
+
function debounce(callback, wait) {
|
|
575
|
+
let timeoutId;
|
|
576
|
+
return (...args) => {
|
|
577
|
+
window.clearTimeout(timeoutId);
|
|
578
|
+
timeoutId = window.setTimeout(() => callback(...args), wait);
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function isExternalLocation(location) {
|
|
582
|
+
return new URL(location, window.location.href).origin !== window.location.origin;
|
|
583
|
+
}
|
|
584
|
+
function normalizeRedirectLocation(location) {
|
|
585
|
+
if (PROTOCOL_RELATIVE_URL_REGEX.test(location)) {
|
|
586
|
+
let path = resolvePath(location);
|
|
587
|
+
return path.pathname + path.search + path.hash;
|
|
588
|
+
}
|
|
589
|
+
return location;
|
|
590
|
+
}
|
|
591
|
+
function cloneRoutes(routes) {
|
|
592
|
+
if (!routes) return void 0;
|
|
593
|
+
return routes.map((route) => ({
|
|
594
|
+
...route,
|
|
595
|
+
children: cloneRoutes(route.children)
|
|
596
|
+
}));
|
|
597
|
+
}
|
|
598
|
+
function diffRoutes(a, b) {
|
|
599
|
+
if (a.length !== b.length) return true;
|
|
600
|
+
return a.some((route, index) => {
|
|
601
|
+
if (route.element !== b[index].element) return true;
|
|
602
|
+
if (route.errorElement !== b[index].errorElement) return true;
|
|
603
|
+
if (route.hydrateFallbackElement !== b[index].hydrateFallbackElement) return true;
|
|
604
|
+
if (route.hasLoader !== b[index].hasLoader) return true;
|
|
605
|
+
if (route.hasClientLoader !== b[index].hasClientLoader) return true;
|
|
606
|
+
if (route.hasAction !== b[index].hasAction) return true;
|
|
607
|
+
if (route.hasClientAction !== b[index].hasClientAction) return true;
|
|
608
|
+
return diffRoutes(route.children || [], b[index].children || []);
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
//#endregion
|
|
612
|
+
export { RSCHydratedRouter, createCallServer };
|