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,152 @@
|
|
|
1
|
+
|
|
2
|
+
import { RSCPayload } from "./server.rsc.js";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
|
|
5
|
+
//#region lib/rsc/server.ssr.d.ts
|
|
6
|
+
type DecodedPayload = Promise<RSCPayload> & {
|
|
7
|
+
_deepestRenderedBoundaryId?: string | null;
|
|
8
|
+
formState: Promise<any>;
|
|
9
|
+
};
|
|
10
|
+
type SSRCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Routes the incoming [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
13
|
+
* to the [RSC](https://react.dev/reference/rsc/server-components) server and
|
|
14
|
+
* appropriately proxies the server response for data / resource requests, or
|
|
15
|
+
* renders to HTML for a document request.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
19
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
20
|
+
* import {
|
|
21
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
22
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
23
|
+
* } from "react-router";
|
|
24
|
+
*
|
|
25
|
+
* routeRSCServerRequest({
|
|
26
|
+
* request,
|
|
27
|
+
* serverResponse,
|
|
28
|
+
* createFromReadableStream,
|
|
29
|
+
* nonce,
|
|
30
|
+
* async renderHTML(getPayload, options) {
|
|
31
|
+
* const payload = getPayload();
|
|
32
|
+
*
|
|
33
|
+
* return await renderHTMLToReadableStream(
|
|
34
|
+
* <RSCStaticRouter
|
|
35
|
+
* getPayload={getPayload}
|
|
36
|
+
* nonce={options.nonce}
|
|
37
|
+
* />,
|
|
38
|
+
* {
|
|
39
|
+
* ...options,
|
|
40
|
+
* bootstrapScriptContent,
|
|
41
|
+
* formState: await payload.formState,
|
|
42
|
+
* }
|
|
43
|
+
* );
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* @name unstable_routeRSCServerRequest
|
|
48
|
+
* @public
|
|
49
|
+
* @category RSC
|
|
50
|
+
* @mode data
|
|
51
|
+
* @param opts Options
|
|
52
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
53
|
+
* `createFromReadableStream` function, used to decode payloads from the server.
|
|
54
|
+
* @param opts.serverResponse A Response or partial response generated by the [RSC](https://react.dev/reference/rsc/server-components) handler containing a serialized {@link unstable_RSCPayload}.
|
|
55
|
+
* @param opts.hydrate Whether to hydrate the server response with the RSC payload.
|
|
56
|
+
* Defaults to `true`.
|
|
57
|
+
* @param opts.nonce An optional [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
58
|
+
* for inline scripts generated while rendering the HTML document.
|
|
59
|
+
* @param opts.renderHTML A function that renders the {@link unstable_RSCPayload} to
|
|
60
|
+
* HTML, usually using a {@link unstable_RSCStaticRouter | `<RSCStaticRouter>`}.
|
|
61
|
+
* @param opts.request The request to route.
|
|
62
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
63
|
+
* that either contains the [RSC](https://react.dev/reference/rsc/server-components)
|
|
64
|
+
* payload for data requests, or renders the HTML for document requests.
|
|
65
|
+
*/
|
|
66
|
+
declare function routeRSCServerRequest({
|
|
67
|
+
request,
|
|
68
|
+
serverResponse,
|
|
69
|
+
createFromReadableStream,
|
|
70
|
+
renderHTML,
|
|
71
|
+
hydrate,
|
|
72
|
+
nonce
|
|
73
|
+
}: {
|
|
74
|
+
request: Request;
|
|
75
|
+
serverResponse: Response;
|
|
76
|
+
createFromReadableStream: SSRCreateFromReadableStreamFunction;
|
|
77
|
+
renderHTML: (getPayload: () => DecodedPayload, options: {
|
|
78
|
+
nonce?: string;
|
|
79
|
+
onError(error: unknown): string | undefined;
|
|
80
|
+
onHeaders(headers: Headers): void;
|
|
81
|
+
}) => ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>;
|
|
82
|
+
hydrate?: boolean;
|
|
83
|
+
nonce?: string;
|
|
84
|
+
}): Promise<Response>;
|
|
85
|
+
/**
|
|
86
|
+
* Props for the {@link unstable_RSCStaticRouter} component.
|
|
87
|
+
*
|
|
88
|
+
* @name unstable_RSCStaticRouterProps
|
|
89
|
+
* @category Types
|
|
90
|
+
*/
|
|
91
|
+
interface RSCStaticRouterProps {
|
|
92
|
+
/**
|
|
93
|
+
* A function that starts decoding of the {@link unstable_RSCPayload}. Usually passed
|
|
94
|
+
* through from {@link unstable_routeRSCServerRequest}'s `renderHTML`.
|
|
95
|
+
*/
|
|
96
|
+
getPayload: () => DecodedPayload;
|
|
97
|
+
/**
|
|
98
|
+
* An optional [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
99
|
+
* used as the default for nonce-aware components such as `<Links>` and
|
|
100
|
+
* `<ScrollRestoration>`.
|
|
101
|
+
*/
|
|
102
|
+
nonce?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Pre-renders an {@link unstable_RSCPayload} to HTML. Usually used in
|
|
106
|
+
* {@link unstable_routeRSCServerRequest}'s `renderHTML` callback.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
110
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
111
|
+
* import {
|
|
112
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
113
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
114
|
+
* } from "react-router";
|
|
115
|
+
*
|
|
116
|
+
* routeRSCServerRequest({
|
|
117
|
+
* request,
|
|
118
|
+
* serverResponse,
|
|
119
|
+
* createFromReadableStream,
|
|
120
|
+
* nonce,
|
|
121
|
+
* async renderHTML(getPayload, options) {
|
|
122
|
+
* const payload = getPayload();
|
|
123
|
+
*
|
|
124
|
+
* return await renderHTMLToReadableStream(
|
|
125
|
+
* <RSCStaticRouter
|
|
126
|
+
* getPayload={getPayload}
|
|
127
|
+
* nonce={options.nonce}
|
|
128
|
+
* />,
|
|
129
|
+
* {
|
|
130
|
+
* ...options,
|
|
131
|
+
* bootstrapScriptContent,
|
|
132
|
+
* formState: await payload.formState,
|
|
133
|
+
* }
|
|
134
|
+
* );
|
|
135
|
+
* },
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* @name unstable_RSCStaticRouter
|
|
139
|
+
* @public
|
|
140
|
+
* @category RSC
|
|
141
|
+
* @mode data
|
|
142
|
+
* @param props Props
|
|
143
|
+
* @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
|
|
144
|
+
* @param {unstable_RSCStaticRouterProps.nonce} props.nonce n/a
|
|
145
|
+
* @returns A React component that renders the {@link unstable_RSCPayload} as HTML.
|
|
146
|
+
*/
|
|
147
|
+
declare function RSCStaticRouter({
|
|
148
|
+
getPayload,
|
|
149
|
+
nonce
|
|
150
|
+
}: RSCStaticRouterProps): React$1.JSX.Element | null;
|
|
151
|
+
//#endregion
|
|
152
|
+
export { RSCStaticRouter, RSCStaticRouterProps, SSRCreateFromReadableStreamFunction, routeRSCServerRequest };
|
|
@@ -0,0 +1,419 @@
|
|
|
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 { isRouteErrorResponse } from "../router/utils.js";
|
|
12
|
+
import { hasInvalidProtocol } from "../router/router.js";
|
|
13
|
+
import { RSCRouterContext } from "../context.js";
|
|
14
|
+
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "../errors.js";
|
|
15
|
+
import { escapeHtml } from "../dom/ssr/markup.js";
|
|
16
|
+
import { shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
|
|
17
|
+
import { FrameworkContext } from "../dom/ssr/components.js";
|
|
18
|
+
import { StaticRouterProvider, createStaticRouter } from "../dom/server.js";
|
|
19
|
+
import { injectRSCPayload } from "./html-stream/server.js";
|
|
20
|
+
import { RSCRouterGlobalErrorBoundary } from "./errorBoundaries.js";
|
|
21
|
+
import { createRSCRouteModules } from "./route-modules.js";
|
|
22
|
+
import * as React$1 from "react";
|
|
23
|
+
//#region lib/rsc/server.ssr.tsx
|
|
24
|
+
const defaultManifestPath = "/__manifest";
|
|
25
|
+
/**
|
|
26
|
+
* Routes the incoming [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
27
|
+
* to the [RSC](https://react.dev/reference/rsc/server-components) server and
|
|
28
|
+
* appropriately proxies the server response for data / resource requests, or
|
|
29
|
+
* renders to HTML for a document request.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
33
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
34
|
+
* import {
|
|
35
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
36
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
37
|
+
* } from "react-router";
|
|
38
|
+
*
|
|
39
|
+
* routeRSCServerRequest({
|
|
40
|
+
* request,
|
|
41
|
+
* serverResponse,
|
|
42
|
+
* createFromReadableStream,
|
|
43
|
+
* nonce,
|
|
44
|
+
* async renderHTML(getPayload, options) {
|
|
45
|
+
* const payload = getPayload();
|
|
46
|
+
*
|
|
47
|
+
* return await renderHTMLToReadableStream(
|
|
48
|
+
* <RSCStaticRouter
|
|
49
|
+
* getPayload={getPayload}
|
|
50
|
+
* nonce={options.nonce}
|
|
51
|
+
* />,
|
|
52
|
+
* {
|
|
53
|
+
* ...options,
|
|
54
|
+
* bootstrapScriptContent,
|
|
55
|
+
* formState: await payload.formState,
|
|
56
|
+
* }
|
|
57
|
+
* );
|
|
58
|
+
* },
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* @name unstable_routeRSCServerRequest
|
|
62
|
+
* @public
|
|
63
|
+
* @category RSC
|
|
64
|
+
* @mode data
|
|
65
|
+
* @param opts Options
|
|
66
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
67
|
+
* `createFromReadableStream` function, used to decode payloads from the server.
|
|
68
|
+
* @param opts.serverResponse A Response or partial response generated by the [RSC](https://react.dev/reference/rsc/server-components) handler containing a serialized {@link unstable_RSCPayload}.
|
|
69
|
+
* @param opts.hydrate Whether to hydrate the server response with the RSC payload.
|
|
70
|
+
* Defaults to `true`.
|
|
71
|
+
* @param opts.nonce An optional [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
72
|
+
* for inline scripts generated while rendering the HTML document.
|
|
73
|
+
* @param opts.renderHTML A function that renders the {@link unstable_RSCPayload} to
|
|
74
|
+
* HTML, usually using a {@link unstable_RSCStaticRouter | `<RSCStaticRouter>`}.
|
|
75
|
+
* @param opts.request The request to route.
|
|
76
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
77
|
+
* that either contains the [RSC](https://react.dev/reference/rsc/server-components)
|
|
78
|
+
* payload for data requests, or renders the HTML for document requests.
|
|
79
|
+
*/
|
|
80
|
+
async function routeRSCServerRequest({ request, serverResponse, createFromReadableStream, renderHTML, hydrate = true, nonce }) {
|
|
81
|
+
const url = new URL(request.url);
|
|
82
|
+
if (isReactServerRequest(url) || isManifestRequest(url) || request.headers.has("rsc-action-id") || serverResponse.headers.get("React-Router-Resource") === "true") return serverResponse;
|
|
83
|
+
if (!serverResponse.body) throw new Error("Missing body in server response");
|
|
84
|
+
const detectRedirectResponse = serverResponse.clone();
|
|
85
|
+
let serverResponseB = null;
|
|
86
|
+
if (hydrate) serverResponseB = serverResponse.clone();
|
|
87
|
+
const body = serverResponse.body;
|
|
88
|
+
let buffer;
|
|
89
|
+
let streamControllers = [];
|
|
90
|
+
const createStream = () => {
|
|
91
|
+
if (!buffer) {
|
|
92
|
+
buffer = [];
|
|
93
|
+
return body.pipeThrough(new TransformStream({
|
|
94
|
+
transform(chunk, controller) {
|
|
95
|
+
buffer.push(chunk);
|
|
96
|
+
controller.enqueue(chunk);
|
|
97
|
+
streamControllers.forEach((c) => c.enqueue(chunk));
|
|
98
|
+
},
|
|
99
|
+
flush() {
|
|
100
|
+
streamControllers.forEach((c) => c.close());
|
|
101
|
+
streamControllers = [];
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
return new ReadableStream({ start(controller) {
|
|
106
|
+
buffer.forEach((chunk) => controller.enqueue(chunk));
|
|
107
|
+
streamControllers.push(controller);
|
|
108
|
+
} });
|
|
109
|
+
};
|
|
110
|
+
let deepestRenderedBoundaryId = null;
|
|
111
|
+
const getPayload = () => {
|
|
112
|
+
const payloadPromise = Promise.resolve(createFromReadableStream(createStream()));
|
|
113
|
+
return Object.defineProperties(payloadPromise, {
|
|
114
|
+
_deepestRenderedBoundaryId: {
|
|
115
|
+
get() {
|
|
116
|
+
return deepestRenderedBoundaryId;
|
|
117
|
+
},
|
|
118
|
+
set(boundaryId) {
|
|
119
|
+
deepestRenderedBoundaryId = boundaryId;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
formState: { get() {
|
|
123
|
+
return payloadPromise.then((payload) => payload.type === "render" ? payload.formState : void 0);
|
|
124
|
+
} }
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
let renderRedirect;
|
|
128
|
+
let renderError;
|
|
129
|
+
try {
|
|
130
|
+
if (!detectRedirectResponse.body) throw new Error("Failed to clone server response");
|
|
131
|
+
const payload = await createFromReadableStream(detectRedirectResponse.body);
|
|
132
|
+
if (serverResponse.status === 202 && payload.type === "redirect") {
|
|
133
|
+
if (hasInvalidProtocol(payload.location)) throw new Error("Invalid redirect location");
|
|
134
|
+
const headers = new Headers(serverResponse.headers);
|
|
135
|
+
headers.delete("Content-Encoding");
|
|
136
|
+
headers.delete("Content-Length");
|
|
137
|
+
headers.delete("Content-Type");
|
|
138
|
+
headers.delete("X-Remix-Response");
|
|
139
|
+
headers.set("Location", payload.location);
|
|
140
|
+
return new Response(serverResponseB?.body || "", {
|
|
141
|
+
headers,
|
|
142
|
+
status: payload.status,
|
|
143
|
+
statusText: serverResponse.statusText
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
let reactHeaders = new Headers();
|
|
147
|
+
let status = serverResponse.status;
|
|
148
|
+
let statusText = serverResponse.statusText;
|
|
149
|
+
let html = await renderHTML(getPayload, {
|
|
150
|
+
nonce,
|
|
151
|
+
onError(error) {
|
|
152
|
+
if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
|
153
|
+
renderRedirect = decodeRedirectErrorDigest(error.digest);
|
|
154
|
+
if (renderRedirect) return error.digest;
|
|
155
|
+
let routeErrorResponse = decodeRouteErrorResponseDigest(error.digest);
|
|
156
|
+
if (routeErrorResponse) {
|
|
157
|
+
renderError = routeErrorResponse;
|
|
158
|
+
status = routeErrorResponse.status;
|
|
159
|
+
statusText = routeErrorResponse.statusText;
|
|
160
|
+
return error.digest;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
onHeaders(headers) {
|
|
165
|
+
for (const [key, value] of headers) reactHeaders.append(key, value);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const headers = new Headers(reactHeaders);
|
|
169
|
+
for (const [key, value] of serverResponse.headers) headers.append(key, value);
|
|
170
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
171
|
+
if (renderRedirect) {
|
|
172
|
+
if (hasInvalidProtocol(renderRedirect.location)) throw new Error("Invalid redirect location");
|
|
173
|
+
headers.set("Location", renderRedirect.location);
|
|
174
|
+
return new Response(html, {
|
|
175
|
+
status: renderRedirect.status,
|
|
176
|
+
headers
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const redirectTransform = new TransformStream({ flush(controller) {
|
|
180
|
+
if (renderRedirect) {
|
|
181
|
+
if (hasInvalidProtocol(renderRedirect.location)) return;
|
|
182
|
+
controller.enqueue(new TextEncoder().encode(`<meta http-equiv="refresh" content="0;url=${escapeHtml(renderRedirect.location)}"/>`));
|
|
183
|
+
}
|
|
184
|
+
} });
|
|
185
|
+
if (!hydrate) return new Response(html.pipeThrough(redirectTransform), {
|
|
186
|
+
status,
|
|
187
|
+
statusText,
|
|
188
|
+
headers
|
|
189
|
+
});
|
|
190
|
+
if (!serverResponseB?.body) throw new Error("Failed to clone server response");
|
|
191
|
+
const body = html.pipeThrough(injectRSCPayload(serverResponseB.body, { nonce })).pipeThrough(redirectTransform);
|
|
192
|
+
return new Response(body, {
|
|
193
|
+
status,
|
|
194
|
+
statusText,
|
|
195
|
+
headers
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (error instanceof Response) return error;
|
|
199
|
+
if (renderRedirect) {
|
|
200
|
+
if (hasInvalidProtocol(renderRedirect.location)) throw new Error("Invalid redirect location");
|
|
201
|
+
return new Response(`Redirect: ${renderRedirect.location}`, {
|
|
202
|
+
status: renderRedirect.status,
|
|
203
|
+
headers: { Location: renderRedirect.location }
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
let normalizedError = renderError ?? error;
|
|
208
|
+
let [status, statusText] = isRouteErrorResponse(normalizedError) ? [normalizedError.status, normalizedError.statusText] : [500, ""];
|
|
209
|
+
let retryRedirect;
|
|
210
|
+
let reactHeaders = new Headers();
|
|
211
|
+
const html = await renderHTML(() => {
|
|
212
|
+
const payloadPromise = Promise.resolve(createFromReadableStream(createStream())).then((payload) => Object.assign(payload, {
|
|
213
|
+
status,
|
|
214
|
+
errors: deepestRenderedBoundaryId ? { [deepestRenderedBoundaryId]: normalizedError } : {}
|
|
215
|
+
}));
|
|
216
|
+
return Object.defineProperties(payloadPromise, {
|
|
217
|
+
_deepestRenderedBoundaryId: {
|
|
218
|
+
get() {
|
|
219
|
+
return deepestRenderedBoundaryId;
|
|
220
|
+
},
|
|
221
|
+
set(boundaryId) {
|
|
222
|
+
deepestRenderedBoundaryId = boundaryId;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
formState: { get() {
|
|
226
|
+
return payloadPromise.then((payload) => payload.type === "render" ? payload.formState : void 0);
|
|
227
|
+
} }
|
|
228
|
+
});
|
|
229
|
+
}, {
|
|
230
|
+
nonce,
|
|
231
|
+
onError(error) {
|
|
232
|
+
if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
|
233
|
+
retryRedirect = decodeRedirectErrorDigest(error.digest);
|
|
234
|
+
if (retryRedirect) return error.digest;
|
|
235
|
+
let routeErrorResponse = decodeRouteErrorResponseDigest(error.digest);
|
|
236
|
+
if (routeErrorResponse) {
|
|
237
|
+
status = routeErrorResponse.status;
|
|
238
|
+
statusText = routeErrorResponse.statusText;
|
|
239
|
+
return error.digest;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
onHeaders(headers) {
|
|
244
|
+
for (const [key, value] of headers) reactHeaders.append(key, value);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const headers = new Headers(reactHeaders);
|
|
248
|
+
for (const [key, value] of serverResponse.headers) headers.append(key, value);
|
|
249
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
250
|
+
if (retryRedirect) {
|
|
251
|
+
if (hasInvalidProtocol(retryRedirect.location)) throw new Error("Invalid redirect location");
|
|
252
|
+
headers.set("Location", retryRedirect.location);
|
|
253
|
+
return new Response(html, {
|
|
254
|
+
status: retryRedirect.status,
|
|
255
|
+
headers
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const retryRedirectTransform = new TransformStream({ flush(controller) {
|
|
259
|
+
if (retryRedirect) {
|
|
260
|
+
if (hasInvalidProtocol(retryRedirect.location)) return;
|
|
261
|
+
controller.enqueue(new TextEncoder().encode(`<meta http-equiv="refresh" content="0;url=${escapeHtml(retryRedirect.location)}"/>`));
|
|
262
|
+
}
|
|
263
|
+
} });
|
|
264
|
+
if (!hydrate) return new Response(html.pipeThrough(retryRedirectTransform), {
|
|
265
|
+
status,
|
|
266
|
+
statusText,
|
|
267
|
+
headers
|
|
268
|
+
});
|
|
269
|
+
if (!serverResponseB?.body) throw new Error("Failed to clone server response");
|
|
270
|
+
const body = html.pipeThrough(injectRSCPayload(serverResponseB.body, { nonce })).pipeThrough(retryRedirectTransform);
|
|
271
|
+
return new Response(body, {
|
|
272
|
+
status,
|
|
273
|
+
statusText,
|
|
274
|
+
headers
|
|
275
|
+
});
|
|
276
|
+
} catch (error2) {}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Pre-renders an {@link unstable_RSCPayload} to HTML. Usually used in
|
|
282
|
+
* {@link unstable_routeRSCServerRequest}'s `renderHTML` callback.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
286
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
287
|
+
* import {
|
|
288
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
289
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
290
|
+
* } from "react-router";
|
|
291
|
+
*
|
|
292
|
+
* routeRSCServerRequest({
|
|
293
|
+
* request,
|
|
294
|
+
* serverResponse,
|
|
295
|
+
* createFromReadableStream,
|
|
296
|
+
* nonce,
|
|
297
|
+
* async renderHTML(getPayload, options) {
|
|
298
|
+
* const payload = getPayload();
|
|
299
|
+
*
|
|
300
|
+
* return await renderHTMLToReadableStream(
|
|
301
|
+
* <RSCStaticRouter
|
|
302
|
+
* getPayload={getPayload}
|
|
303
|
+
* nonce={options.nonce}
|
|
304
|
+
* />,
|
|
305
|
+
* {
|
|
306
|
+
* ...options,
|
|
307
|
+
* bootstrapScriptContent,
|
|
308
|
+
* formState: await payload.formState,
|
|
309
|
+
* }
|
|
310
|
+
* );
|
|
311
|
+
* },
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* @name unstable_RSCStaticRouter
|
|
315
|
+
* @public
|
|
316
|
+
* @category RSC
|
|
317
|
+
* @mode data
|
|
318
|
+
* @param props Props
|
|
319
|
+
* @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
|
|
320
|
+
* @param {unstable_RSCStaticRouterProps.nonce} props.nonce n/a
|
|
321
|
+
* @returns A React component that renders the {@link unstable_RSCPayload} as HTML.
|
|
322
|
+
*/
|
|
323
|
+
function RSCStaticRouter({ getPayload, nonce }) {
|
|
324
|
+
const decoded = getPayload();
|
|
325
|
+
const payload = React$1.use(decoded);
|
|
326
|
+
if (payload.type === "redirect") {
|
|
327
|
+
if (hasInvalidProtocol(payload.location)) throw new Error("Invalid redirect location");
|
|
328
|
+
throw new Response(null, {
|
|
329
|
+
status: payload.status,
|
|
330
|
+
headers: { Location: payload.location }
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
if (payload.type !== "render") return null;
|
|
334
|
+
let patchedLoaderData = { ...payload.loaderData };
|
|
335
|
+
for (const match of payload.matches) if (shouldHydrateRouteLoader(match.id, match.clientLoader, match.hasLoader, false) && (match.hydrateFallbackElement || !match.hasLoader)) delete patchedLoaderData[match.id];
|
|
336
|
+
const context = {
|
|
337
|
+
get _deepestRenderedBoundaryId() {
|
|
338
|
+
return decoded._deepestRenderedBoundaryId ?? null;
|
|
339
|
+
},
|
|
340
|
+
set _deepestRenderedBoundaryId(boundaryId) {
|
|
341
|
+
decoded._deepestRenderedBoundaryId = boundaryId;
|
|
342
|
+
},
|
|
343
|
+
actionData: payload.actionData,
|
|
344
|
+
actionHeaders: {},
|
|
345
|
+
basename: payload.basename,
|
|
346
|
+
errors: payload.errors,
|
|
347
|
+
loaderData: patchedLoaderData,
|
|
348
|
+
loaderHeaders: {},
|
|
349
|
+
location: payload.location,
|
|
350
|
+
statusCode: 200,
|
|
351
|
+
matches: payload.matches.map((match) => ({
|
|
352
|
+
params: match.params,
|
|
353
|
+
pathname: match.pathname,
|
|
354
|
+
pathnameBase: match.pathnameBase,
|
|
355
|
+
route: {
|
|
356
|
+
id: match.id,
|
|
357
|
+
action: match.hasAction || !!match.clientAction,
|
|
358
|
+
handle: match.handle,
|
|
359
|
+
loader: match.hasLoader || !!match.clientLoader,
|
|
360
|
+
index: match.index,
|
|
361
|
+
path: match.path,
|
|
362
|
+
shouldRevalidate: match.shouldRevalidate
|
|
363
|
+
}
|
|
364
|
+
}))
|
|
365
|
+
};
|
|
366
|
+
const router = createStaticRouter(payload.matches.reduceRight((previous, match) => {
|
|
367
|
+
const route = {
|
|
368
|
+
id: match.id,
|
|
369
|
+
action: match.hasAction || !!match.clientAction,
|
|
370
|
+
element: match.element,
|
|
371
|
+
errorElement: match.errorElement,
|
|
372
|
+
handle: match.handle,
|
|
373
|
+
hydrateFallbackElement: match.hydrateFallbackElement,
|
|
374
|
+
index: match.index,
|
|
375
|
+
loader: match.hasLoader || !!match.clientLoader,
|
|
376
|
+
path: match.path,
|
|
377
|
+
shouldRevalidate: match.shouldRevalidate
|
|
378
|
+
};
|
|
379
|
+
if (previous.length > 0) route.children = previous;
|
|
380
|
+
return [route];
|
|
381
|
+
}, []), context);
|
|
382
|
+
const frameworkContext = {
|
|
383
|
+
future: {},
|
|
384
|
+
isSpaMode: false,
|
|
385
|
+
ssr: true,
|
|
386
|
+
criticalCss: "",
|
|
387
|
+
manifest: {
|
|
388
|
+
routes: {},
|
|
389
|
+
version: "1",
|
|
390
|
+
url: "",
|
|
391
|
+
entry: {
|
|
392
|
+
module: "",
|
|
393
|
+
imports: []
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
routeDiscovery: payload.routeDiscovery.mode === "initial" ? {
|
|
397
|
+
mode: "initial",
|
|
398
|
+
manifestPath: defaultManifestPath
|
|
399
|
+
} : {
|
|
400
|
+
mode: "lazy",
|
|
401
|
+
manifestPath: payload.routeDiscovery.manifestPath || defaultManifestPath
|
|
402
|
+
},
|
|
403
|
+
routeModules: createRSCRouteModules(payload),
|
|
404
|
+
nonce
|
|
405
|
+
};
|
|
406
|
+
return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
|
|
407
|
+
context,
|
|
408
|
+
router,
|
|
409
|
+
hydrate: false
|
|
410
|
+
}))));
|
|
411
|
+
}
|
|
412
|
+
function isReactServerRequest(url) {
|
|
413
|
+
return url.pathname.endsWith(".rsc");
|
|
414
|
+
}
|
|
415
|
+
function isManifestRequest(url) {
|
|
416
|
+
return url.pathname.endsWith(".manifest");
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
export { RSCStaticRouter, routeRSCServerRequest };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
import { ActionFunctionArgs, LoaderFunctionArgs, RouterContextProvider } from "../router/utils.js";
|
|
3
|
+
import { AssetsManifest, CriticalCss, EntryContext, FutureConfig } from "../dom/ssr/entry.js";
|
|
4
|
+
import { ServerRouteManifest } from "./routes.js";
|
|
5
|
+
import { ServerInstrumentation } from "../router/instrumentation.js";
|
|
6
|
+
|
|
7
|
+
//#region lib/server-runtime/build.d.ts
|
|
8
|
+
type OptionalCriticalCss = CriticalCss | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The output of the compiler for the server build.
|
|
11
|
+
*/
|
|
12
|
+
interface ServerBuild {
|
|
13
|
+
entry: {
|
|
14
|
+
module: ServerEntryModule;
|
|
15
|
+
};
|
|
16
|
+
routes: ServerRouteManifest;
|
|
17
|
+
assets: AssetsManifest;
|
|
18
|
+
basename?: string;
|
|
19
|
+
publicPath: string;
|
|
20
|
+
assetsBuildDirectory: string;
|
|
21
|
+
future: FutureConfig;
|
|
22
|
+
ssr: boolean;
|
|
23
|
+
unstable_getCriticalCss?: (args: {
|
|
24
|
+
pathname: string;
|
|
25
|
+
}) => OptionalCriticalCss | Promise<OptionalCriticalCss>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated This is now done via a custom header during prerendering
|
|
28
|
+
*/
|
|
29
|
+
isSpaMode: boolean;
|
|
30
|
+
prerender: string[];
|
|
31
|
+
routeDiscovery: {
|
|
32
|
+
mode: "lazy" | "initial";
|
|
33
|
+
manifestPath: string;
|
|
34
|
+
};
|
|
35
|
+
allowedActionOrigins?: string[] | false;
|
|
36
|
+
}
|
|
37
|
+
interface HandleDocumentRequestFunction {
|
|
38
|
+
(request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: RouterContextProvider): Promise<Response> | Response;
|
|
39
|
+
}
|
|
40
|
+
interface HandleDataRequestFunction {
|
|
41
|
+
(response: Response, args: {
|
|
42
|
+
request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
|
|
43
|
+
context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
|
|
44
|
+
params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
|
|
45
|
+
}): Promise<Response> | Response;
|
|
46
|
+
}
|
|
47
|
+
interface HandleErrorFunction {
|
|
48
|
+
(error: unknown, args: {
|
|
49
|
+
request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
|
|
50
|
+
context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
|
|
51
|
+
params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
|
|
52
|
+
}): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A module that serves as the entry point for a Remix app during server
|
|
56
|
+
* rendering.
|
|
57
|
+
*/
|
|
58
|
+
interface ServerEntryModule {
|
|
59
|
+
default: HandleDocumentRequestFunction;
|
|
60
|
+
handleDataRequest?: HandleDataRequestFunction;
|
|
61
|
+
handleError?: HandleErrorFunction;
|
|
62
|
+
instrumentations?: ServerInstrumentation[];
|
|
63
|
+
streamTimeout?: number;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, ServerBuild, ServerEntryModule };
|