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