react-router 7.16.0 → 8.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1007
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1645 -1635
- package/dist/development/index-react-server.js +2880 -3642
- package/dist/development/index.d.ts +43 -1475
- package/dist/development/index.js +37 -2621
- package/dist/development/lib/actions.js +62 -0
- package/dist/development/lib/components.d.ts +1022 -0
- package/dist/development/lib/components.js +835 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2042 -0
- package/dist/development/lib/dom/lib.js +1259 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +196 -0
- package/dist/development/lib/dom/ssr/components.js +579 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/development/lib/dom/ssr/errors.js +36 -0
- package/dist/development/lib/dom/ssr/fallback.js +28 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +45 -0
- package/dist/development/lib/dom/ssr/server.js +68 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +153 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1386 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +371 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +113 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2981 -0
- package/dist/development/lib/router/utils.d.ts +942 -0
- package/dist/development/lib/router/utils.js +791 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +599 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +388 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +95 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +351 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +31 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/{production/register-CNAx3TXj.d.ts → development/lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1007
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1645 -1635
- package/dist/production/index-react-server.js +2871 -3642
- package/dist/production/index.d.ts +43 -1475
- package/dist/production/index.js +37 -2621
- package/dist/production/lib/actions.js +62 -0
- package/dist/production/lib/components.d.ts +1022 -0
- package/dist/production/lib/components.js +835 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2042 -0
- package/dist/production/lib/dom/lib.js +1259 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +196 -0
- package/dist/production/lib/dom/ssr/components.js +579 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/production/lib/dom/ssr/errors.js +36 -0
- package/dist/production/lib/dom/ssr/fallback.js +21 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +45 -0
- package/dist/production/lib/dom/ssr/server.js +68 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +153 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1371 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +371 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +113 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2981 -0
- package/dist/production/lib/router/utils.d.ts +942 -0
- package/dist/production/lib/router/utils.js +782 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +599 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +388 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +95 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +351 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +31 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/{development/register-CNAx3TXj.d.ts → production/lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
- package/docs/explanation/backend-for-frontend.md +50 -0
- package/docs/explanation/code-splitting.md +77 -0
- package/docs/explanation/concurrency.md +135 -0
- package/docs/explanation/form-vs-fetcher.md +292 -0
- package/docs/explanation/hot-module-replacement.md +137 -0
- package/docs/explanation/hydration.md +14 -0
- package/docs/explanation/index-query-param.md +86 -0
- package/docs/explanation/index.md +4 -0
- package/docs/explanation/lazy-route-discovery.md +78 -0
- package/docs/explanation/location.md +6 -0
- package/docs/explanation/progressive-enhancement.md +150 -0
- package/docs/explanation/race-conditions.md +88 -0
- package/docs/explanation/react-transitions.md +160 -0
- package/docs/explanation/route-matching.md +7 -0
- package/docs/explanation/server-client-execution.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +465 -0
- package/docs/explanation/special-files.md +16 -0
- package/docs/explanation/state-management.md +524 -0
- package/docs/explanation/styling.md +87 -0
- package/docs/explanation/type-safety.md +82 -0
- package/docs/how-to/accessibility.md +44 -0
- package/docs/how-to/client-data.md +199 -0
- package/docs/how-to/data-strategy.md +317 -0
- package/docs/how-to/error-boundary.md +231 -0
- package/docs/how-to/error-reporting.md +134 -0
- package/docs/how-to/fetchers.md +307 -0
- package/docs/how-to/file-route-conventions.md +410 -0
- package/docs/how-to/file-uploads.md +217 -0
- package/docs/how-to/form-validation.md +120 -0
- package/docs/how-to/headers.md +164 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +556 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +728 -0
- package/docs/how-to/navigation-blocking.md +233 -0
- package/docs/how-to/optimize-revalidation.md +12 -0
- package/docs/how-to/pre-rendering.md +225 -0
- package/docs/how-to/presets.md +103 -0
- package/docs/how-to/react-server-components.md +899 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +100 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +30 -0
- package/docs/how-to/server-bundles.md +66 -0
- package/docs/how-to/spa.md +120 -0
- package/docs/how-to/status.md +63 -0
- package/docs/how-to/suspense.md +132 -0
- package/docs/how-to/using-handle.md +117 -0
- package/docs/how-to/view-transitions.md +237 -0
- package/docs/how-to/webhook.md +50 -0
- package/docs/index.md +39 -0
- package/docs/start/data/actions.md +138 -0
- package/docs/start/data/custom.md +198 -0
- package/docs/start/data/data-loading.md +44 -0
- package/docs/start/data/index.md +4 -0
- package/docs/start/data/installation.md +52 -0
- package/docs/start/data/navigating.md +12 -0
- package/docs/start/data/pending-ui.md +12 -0
- package/docs/start/data/route-object.md +248 -0
- package/docs/start/data/routing.md +281 -0
- package/docs/start/data/testing.md +8 -0
- package/docs/start/declarative/index.md +4 -0
- package/docs/start/declarative/installation.md +43 -0
- package/docs/start/declarative/navigating.md +133 -0
- package/docs/start/declarative/routing.md +237 -0
- package/docs/start/declarative/url-values.md +65 -0
- package/docs/start/framework/actions.md +175 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +96 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +42 -0
- package/docs/start/framework/navigating.md +182 -0
- package/docs/start/framework/pending-ui.md +142 -0
- package/docs/start/framework/rendering.md +59 -0
- package/docs/start/framework/route-module.md +527 -0
- package/docs/start/framework/routing.md +362 -0
- package/docs/start/framework/testing.md +133 -0
- package/docs/start/index.md +4 -0
- package/docs/start/modes.md +201 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +31 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/remix.md +403 -0
- package/docs/upgrading/router-provider.md +442 -0
- package/docs/upgrading/v6.md +379 -0
- package/package.json +44 -87
- package/dist/development/browser-D3uq9sI1.d.ts +0 -318
- package/dist/development/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/development/chunk-IBI7OMNB.js +0 -1363
- package/dist/development/chunk-QUQL4437.mjs +0 -11529
- package/dist/development/chunk-S54KXAEJ.mjs +0 -2585
- package/dist/development/chunk-SRID2YZ2.js +0 -10229
- package/dist/development/chunk-XEJDWL2B.js +0 -188
- package/dist/development/context-m8rizgnE.d.mts +0 -1771
- package/dist/development/data-D4xhSy90.d.ts +0 -1732
- package/dist/development/data-U8FS-wNn.d.mts +0 -1732
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1008
- package/dist/development/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/development/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2703
- package/dist/development/index-react-server.mjs +0 -3780
- package/dist/development/index.d.mts +0 -1478
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-CqK96Zfk.d.mts +0 -30
- package/dist/production/browser-D3uq9sI1.d.ts +0 -318
- package/dist/production/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/production/chunk-EAQNHM3N.js +0 -188
- package/dist/production/chunk-NALGHHKE.mjs +0 -2585
- package/dist/production/chunk-Q65P7S7Y.mjs +0 -11529
- package/dist/production/chunk-SKEDDLRM.js +0 -1363
- package/dist/production/chunk-Y7DNFQZP.js +0 -10229
- package/dist/production/context-m8rizgnE.d.mts +0 -1771
- package/dist/production/data-D4xhSy90.d.ts +0 -1732
- package/dist/production/data-U8FS-wNn.d.mts +0 -1732
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1008
- package/dist/production/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/production/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2703
- package/dist/production/index-react-server.mjs +0 -3780
- package/dist/production/index.d.mts +0 -1478
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-CqK96Zfk.d.mts +0 -30
|
@@ -0,0 +1,388 @@
|
|
|
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 { RSCRouterContext } from "../context.js";
|
|
13
|
+
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "../errors.js";
|
|
14
|
+
import { escapeHtml } from "../dom/ssr/markup.js";
|
|
15
|
+
import { shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
|
|
16
|
+
import { FrameworkContext } from "../dom/ssr/components.js";
|
|
17
|
+
import { StaticRouterProvider, createStaticRouter } from "../dom/server.js";
|
|
18
|
+
import { injectRSCPayload } from "./html-stream/server.js";
|
|
19
|
+
import { RSCRouterGlobalErrorBoundary } from "./errorBoundaries.js";
|
|
20
|
+
import { createRSCRouteModules } from "./route-modules.js";
|
|
21
|
+
import * as React$1 from "react";
|
|
22
|
+
//#region lib/rsc/server.ssr.tsx
|
|
23
|
+
const defaultManifestPath = "/__manifest";
|
|
24
|
+
/**
|
|
25
|
+
* Routes the incoming [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
26
|
+
* to the [RSC](https://react.dev/reference/rsc/server-components) server and
|
|
27
|
+
* appropriately proxies the server response for data / resource requests, or
|
|
28
|
+
* renders to HTML for a document request.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
32
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
33
|
+
* import {
|
|
34
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
35
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
36
|
+
* } from "react-router";
|
|
37
|
+
*
|
|
38
|
+
* routeRSCServerRequest({
|
|
39
|
+
* request,
|
|
40
|
+
* serverResponse,
|
|
41
|
+
* createFromReadableStream,
|
|
42
|
+
* async renderHTML(getPayload) {
|
|
43
|
+
* const payload = getPayload();
|
|
44
|
+
*
|
|
45
|
+
* return await renderHTMLToReadableStream(
|
|
46
|
+
* <RSCStaticRouter getPayload={getPayload} />,
|
|
47
|
+
* {
|
|
48
|
+
* bootstrapScriptContent,
|
|
49
|
+
* formState: await payload.formState,
|
|
50
|
+
* }
|
|
51
|
+
* );
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* @name unstable_routeRSCServerRequest
|
|
56
|
+
* @public
|
|
57
|
+
* @category RSC
|
|
58
|
+
* @mode data
|
|
59
|
+
* @param opts Options
|
|
60
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
61
|
+
* `createFromReadableStream` function, used to decode payloads from the server.
|
|
62
|
+
* @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}.
|
|
63
|
+
* @param opts.hydrate Whether to hydrate the server response with the RSC payload.
|
|
64
|
+
* Defaults to `true`.
|
|
65
|
+
* @param opts.renderHTML A function that renders the {@link unstable_RSCPayload} to
|
|
66
|
+
* HTML, usually using a {@link unstable_RSCStaticRouter | `<RSCStaticRouter>`}.
|
|
67
|
+
* @param opts.request The request to route.
|
|
68
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
69
|
+
* that either contains the [RSC](https://react.dev/reference/rsc/server-components)
|
|
70
|
+
* payload for data requests, or renders the HTML for document requests.
|
|
71
|
+
*/
|
|
72
|
+
async function routeRSCServerRequest({ request, serverResponse, createFromReadableStream, renderHTML, hydrate = true }) {
|
|
73
|
+
const url = new URL(request.url);
|
|
74
|
+
if (isReactServerRequest(url) || isManifestRequest(url) || request.headers.has("rsc-action-id") || serverResponse.headers.get("React-Router-Resource") === "true") return serverResponse;
|
|
75
|
+
if (!serverResponse.body) throw new Error("Missing body in server response");
|
|
76
|
+
const detectRedirectResponse = serverResponse.clone();
|
|
77
|
+
let serverResponseB = null;
|
|
78
|
+
if (hydrate) serverResponseB = serverResponse.clone();
|
|
79
|
+
const body = serverResponse.body;
|
|
80
|
+
let buffer;
|
|
81
|
+
let streamControllers = [];
|
|
82
|
+
const createStream = () => {
|
|
83
|
+
if (!buffer) {
|
|
84
|
+
buffer = [];
|
|
85
|
+
return body.pipeThrough(new TransformStream({
|
|
86
|
+
transform(chunk, controller) {
|
|
87
|
+
buffer.push(chunk);
|
|
88
|
+
controller.enqueue(chunk);
|
|
89
|
+
streamControllers.forEach((c) => c.enqueue(chunk));
|
|
90
|
+
},
|
|
91
|
+
flush() {
|
|
92
|
+
streamControllers.forEach((c) => c.close());
|
|
93
|
+
streamControllers = [];
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
return new ReadableStream({ start(controller) {
|
|
98
|
+
buffer.forEach((chunk) => controller.enqueue(chunk));
|
|
99
|
+
streamControllers.push(controller);
|
|
100
|
+
} });
|
|
101
|
+
};
|
|
102
|
+
let deepestRenderedBoundaryId = null;
|
|
103
|
+
const getPayload = () => {
|
|
104
|
+
const payloadPromise = Promise.resolve(createFromReadableStream(createStream()));
|
|
105
|
+
return Object.defineProperties(payloadPromise, {
|
|
106
|
+
_deepestRenderedBoundaryId: {
|
|
107
|
+
get() {
|
|
108
|
+
return deepestRenderedBoundaryId;
|
|
109
|
+
},
|
|
110
|
+
set(boundaryId) {
|
|
111
|
+
deepestRenderedBoundaryId = boundaryId;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
formState: { get() {
|
|
115
|
+
return payloadPromise.then((payload) => payload.type === "render" ? payload.formState : void 0);
|
|
116
|
+
} }
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
let renderRedirect;
|
|
120
|
+
let renderError;
|
|
121
|
+
try {
|
|
122
|
+
if (!detectRedirectResponse.body) throw new Error("Failed to clone server response");
|
|
123
|
+
const payload = await createFromReadableStream(detectRedirectResponse.body);
|
|
124
|
+
if (serverResponse.status === 202 && payload.type === "redirect") {
|
|
125
|
+
const headers = new Headers(serverResponse.headers);
|
|
126
|
+
headers.delete("Content-Encoding");
|
|
127
|
+
headers.delete("Content-Length");
|
|
128
|
+
headers.delete("Content-Type");
|
|
129
|
+
headers.delete("X-Remix-Response");
|
|
130
|
+
headers.set("Location", payload.location);
|
|
131
|
+
return new Response(serverResponseB?.body || "", {
|
|
132
|
+
headers,
|
|
133
|
+
status: payload.status,
|
|
134
|
+
statusText: serverResponse.statusText
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
let reactHeaders = new Headers();
|
|
138
|
+
let status = serverResponse.status;
|
|
139
|
+
let statusText = serverResponse.statusText;
|
|
140
|
+
let html = await renderHTML(getPayload, {
|
|
141
|
+
onError(error) {
|
|
142
|
+
if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
|
143
|
+
renderRedirect = decodeRedirectErrorDigest(error.digest);
|
|
144
|
+
if (renderRedirect) return error.digest;
|
|
145
|
+
let routeErrorResponse = decodeRouteErrorResponseDigest(error.digest);
|
|
146
|
+
if (routeErrorResponse) {
|
|
147
|
+
renderError = routeErrorResponse;
|
|
148
|
+
status = routeErrorResponse.status;
|
|
149
|
+
statusText = routeErrorResponse.statusText;
|
|
150
|
+
return error.digest;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
onHeaders(headers) {
|
|
155
|
+
for (const [key, value] of headers) reactHeaders.append(key, value);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
const headers = new Headers(reactHeaders);
|
|
159
|
+
for (const [key, value] of serverResponse.headers) headers.append(key, value);
|
|
160
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
161
|
+
if (renderRedirect) {
|
|
162
|
+
headers.set("Location", renderRedirect.location);
|
|
163
|
+
return new Response(html, {
|
|
164
|
+
status: renderRedirect.status,
|
|
165
|
+
headers
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const redirectTransform = new TransformStream({ flush(controller) {
|
|
169
|
+
if (renderRedirect) controller.enqueue(new TextEncoder().encode(`<meta http-equiv="refresh" content="0;url=${escapeHtml(renderRedirect.location)}"/>`));
|
|
170
|
+
} });
|
|
171
|
+
if (!hydrate) return new Response(html.pipeThrough(redirectTransform), {
|
|
172
|
+
status,
|
|
173
|
+
statusText,
|
|
174
|
+
headers
|
|
175
|
+
});
|
|
176
|
+
if (!serverResponseB?.body) throw new Error("Failed to clone server response");
|
|
177
|
+
const body = html.pipeThrough(injectRSCPayload(serverResponseB.body)).pipeThrough(redirectTransform);
|
|
178
|
+
return new Response(body, {
|
|
179
|
+
status,
|
|
180
|
+
statusText,
|
|
181
|
+
headers
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (error instanceof Response) return error;
|
|
185
|
+
if (renderRedirect) return new Response(`Redirect: ${renderRedirect.location}`, {
|
|
186
|
+
status: renderRedirect.status,
|
|
187
|
+
headers: { Location: renderRedirect.location }
|
|
188
|
+
});
|
|
189
|
+
try {
|
|
190
|
+
let normalizedError = renderError ?? error;
|
|
191
|
+
let [status, statusText] = isRouteErrorResponse(normalizedError) ? [normalizedError.status, normalizedError.statusText] : [500, ""];
|
|
192
|
+
let retryRedirect;
|
|
193
|
+
let reactHeaders = new Headers();
|
|
194
|
+
const html = await renderHTML(() => {
|
|
195
|
+
const payloadPromise = Promise.resolve(createFromReadableStream(createStream())).then((payload) => Object.assign(payload, {
|
|
196
|
+
status,
|
|
197
|
+
errors: deepestRenderedBoundaryId ? { [deepestRenderedBoundaryId]: normalizedError } : {}
|
|
198
|
+
}));
|
|
199
|
+
return Object.defineProperties(payloadPromise, {
|
|
200
|
+
_deepestRenderedBoundaryId: {
|
|
201
|
+
get() {
|
|
202
|
+
return deepestRenderedBoundaryId;
|
|
203
|
+
},
|
|
204
|
+
set(boundaryId) {
|
|
205
|
+
deepestRenderedBoundaryId = boundaryId;
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
formState: { get() {
|
|
209
|
+
return payloadPromise.then((payload) => payload.type === "render" ? payload.formState : void 0);
|
|
210
|
+
} }
|
|
211
|
+
});
|
|
212
|
+
}, {
|
|
213
|
+
onError(error) {
|
|
214
|
+
if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
|
215
|
+
retryRedirect = decodeRedirectErrorDigest(error.digest);
|
|
216
|
+
if (retryRedirect) return error.digest;
|
|
217
|
+
let routeErrorResponse = decodeRouteErrorResponseDigest(error.digest);
|
|
218
|
+
if (routeErrorResponse) {
|
|
219
|
+
status = routeErrorResponse.status;
|
|
220
|
+
statusText = routeErrorResponse.statusText;
|
|
221
|
+
return error.digest;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
onHeaders(headers) {
|
|
226
|
+
for (const [key, value] of headers) reactHeaders.append(key, value);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
const headers = new Headers(reactHeaders);
|
|
230
|
+
for (const [key, value] of serverResponse.headers) headers.append(key, value);
|
|
231
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
232
|
+
if (retryRedirect) {
|
|
233
|
+
headers.set("Location", retryRedirect.location);
|
|
234
|
+
return new Response(html, {
|
|
235
|
+
status: retryRedirect.status,
|
|
236
|
+
headers
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const retryRedirectTransform = new TransformStream({ flush(controller) {
|
|
240
|
+
if (retryRedirect) controller.enqueue(new TextEncoder().encode(`<meta http-equiv="refresh" content="0;url=${escapeHtml(retryRedirect.location)}"/>`));
|
|
241
|
+
} });
|
|
242
|
+
if (!hydrate) return new Response(html.pipeThrough(retryRedirectTransform), {
|
|
243
|
+
status,
|
|
244
|
+
statusText,
|
|
245
|
+
headers
|
|
246
|
+
});
|
|
247
|
+
if (!serverResponseB?.body) throw new Error("Failed to clone server response");
|
|
248
|
+
const body = html.pipeThrough(injectRSCPayload(serverResponseB.body)).pipeThrough(retryRedirectTransform);
|
|
249
|
+
return new Response(body, {
|
|
250
|
+
status,
|
|
251
|
+
statusText,
|
|
252
|
+
headers
|
|
253
|
+
});
|
|
254
|
+
} catch (error2) {}
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Pre-renders an {@link unstable_RSCPayload} to HTML. Usually used in
|
|
260
|
+
* {@link unstable_routeRSCServerRequest}'s `renderHTML` callback.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
264
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
265
|
+
* import {
|
|
266
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
267
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
268
|
+
* } from "react-router";
|
|
269
|
+
*
|
|
270
|
+
* routeRSCServerRequest({
|
|
271
|
+
* request,
|
|
272
|
+
* serverResponse,
|
|
273
|
+
* createFromReadableStream,
|
|
274
|
+
* async renderHTML(getPayload) {
|
|
275
|
+
* const payload = getPayload();
|
|
276
|
+
*
|
|
277
|
+
* return await renderHTMLToReadableStream(
|
|
278
|
+
* <RSCStaticRouter getPayload={getPayload} />,
|
|
279
|
+
* {
|
|
280
|
+
* bootstrapScriptContent,
|
|
281
|
+
* formState: await payload.formState,
|
|
282
|
+
* }
|
|
283
|
+
* );
|
|
284
|
+
* },
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* @name unstable_RSCStaticRouter
|
|
288
|
+
* @public
|
|
289
|
+
* @category RSC
|
|
290
|
+
* @mode data
|
|
291
|
+
* @param props Props
|
|
292
|
+
* @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
|
|
293
|
+
* @returns A React component that renders the {@link unstable_RSCPayload} as HTML.
|
|
294
|
+
*/
|
|
295
|
+
function RSCStaticRouter({ getPayload }) {
|
|
296
|
+
const decoded = getPayload();
|
|
297
|
+
const payload = React$1.use(decoded);
|
|
298
|
+
if (payload.type === "redirect") throw new Response(null, {
|
|
299
|
+
status: payload.status,
|
|
300
|
+
headers: { Location: payload.location }
|
|
301
|
+
});
|
|
302
|
+
if (payload.type !== "render") return null;
|
|
303
|
+
let patchedLoaderData = { ...payload.loaderData };
|
|
304
|
+
for (const match of payload.matches) if (shouldHydrateRouteLoader(match.id, match.clientLoader, match.hasLoader, false) && (match.hydrateFallbackElement || !match.hasLoader)) delete patchedLoaderData[match.id];
|
|
305
|
+
const context = {
|
|
306
|
+
get _deepestRenderedBoundaryId() {
|
|
307
|
+
return decoded._deepestRenderedBoundaryId ?? null;
|
|
308
|
+
},
|
|
309
|
+
set _deepestRenderedBoundaryId(boundaryId) {
|
|
310
|
+
decoded._deepestRenderedBoundaryId = boundaryId;
|
|
311
|
+
},
|
|
312
|
+
actionData: payload.actionData,
|
|
313
|
+
actionHeaders: {},
|
|
314
|
+
basename: payload.basename,
|
|
315
|
+
errors: payload.errors,
|
|
316
|
+
loaderData: patchedLoaderData,
|
|
317
|
+
loaderHeaders: {},
|
|
318
|
+
location: payload.location,
|
|
319
|
+
statusCode: 200,
|
|
320
|
+
matches: payload.matches.map((match) => ({
|
|
321
|
+
params: match.params,
|
|
322
|
+
pathname: match.pathname,
|
|
323
|
+
pathnameBase: match.pathnameBase,
|
|
324
|
+
route: {
|
|
325
|
+
id: match.id,
|
|
326
|
+
action: match.hasAction || !!match.clientAction,
|
|
327
|
+
handle: match.handle,
|
|
328
|
+
loader: match.hasLoader || !!match.clientLoader,
|
|
329
|
+
index: match.index,
|
|
330
|
+
path: match.path,
|
|
331
|
+
shouldRevalidate: match.shouldRevalidate
|
|
332
|
+
}
|
|
333
|
+
}))
|
|
334
|
+
};
|
|
335
|
+
const router = createStaticRouter(payload.matches.reduceRight((previous, match) => {
|
|
336
|
+
const route = {
|
|
337
|
+
id: match.id,
|
|
338
|
+
action: match.hasAction || !!match.clientAction,
|
|
339
|
+
element: match.element,
|
|
340
|
+
errorElement: match.errorElement,
|
|
341
|
+
handle: match.handle,
|
|
342
|
+
hydrateFallbackElement: match.hydrateFallbackElement,
|
|
343
|
+
index: match.index,
|
|
344
|
+
loader: match.hasLoader || !!match.clientLoader,
|
|
345
|
+
path: match.path,
|
|
346
|
+
shouldRevalidate: match.shouldRevalidate
|
|
347
|
+
};
|
|
348
|
+
if (previous.length > 0) route.children = previous;
|
|
349
|
+
return [route];
|
|
350
|
+
}, []), context);
|
|
351
|
+
const frameworkContext = {
|
|
352
|
+
future: {},
|
|
353
|
+
isSpaMode: false,
|
|
354
|
+
ssr: true,
|
|
355
|
+
criticalCss: "",
|
|
356
|
+
manifest: {
|
|
357
|
+
routes: {},
|
|
358
|
+
version: "1",
|
|
359
|
+
url: "",
|
|
360
|
+
entry: {
|
|
361
|
+
module: "",
|
|
362
|
+
imports: []
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
routeDiscovery: payload.routeDiscovery.mode === "initial" ? {
|
|
366
|
+
mode: "initial",
|
|
367
|
+
manifestPath: defaultManifestPath
|
|
368
|
+
} : {
|
|
369
|
+
mode: "lazy",
|
|
370
|
+
manifestPath: payload.routeDiscovery.manifestPath || defaultManifestPath
|
|
371
|
+
},
|
|
372
|
+
routeModules: createRSCRouteModules(payload)
|
|
373
|
+
};
|
|
374
|
+
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, {
|
|
375
|
+
context,
|
|
376
|
+
router,
|
|
377
|
+
hydrate: false,
|
|
378
|
+
nonce: payload.nonce
|
|
379
|
+
}))));
|
|
380
|
+
}
|
|
381
|
+
function isReactServerRequest(url) {
|
|
382
|
+
return url.pathname.endsWith(".rsc");
|
|
383
|
+
}
|
|
384
|
+
function isManifestRequest(url) {
|
|
385
|
+
return url.pathname.endsWith(".manifest");
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
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 };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
import { CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
|
|
3
|
+
|
|
4
|
+
//#region lib/server-runtime/cookies.d.ts
|
|
5
|
+
interface CookieSignatureOptions {
|
|
6
|
+
/**
|
|
7
|
+
* An array of secrets that may be used to sign/unsign the value of a cookie.
|
|
8
|
+
*
|
|
9
|
+
* The array makes it easy to rotate secrets. New secrets should be added to
|
|
10
|
+
* the beginning of the array. `cookie.serialize()` will always use the first
|
|
11
|
+
* value in the array, but `cookie.parse()` may use any of them so that
|
|
12
|
+
* cookies that were signed with older secrets still work.
|
|
13
|
+
*/
|
|
14
|
+
secrets?: string[];
|
|
15
|
+
}
|
|
16
|
+
type CookieOptions = CookieParseOptions$1 & CookieSerializeOptions$1 & CookieSignatureOptions;
|
|
17
|
+
/**
|
|
18
|
+
* A HTTP cookie.
|
|
19
|
+
*
|
|
20
|
+
* A Cookie is a logical container for metadata about a HTTP cookie; its name
|
|
21
|
+
* and options. But it doesn't contain a value. Instead, it has `parse()` and
|
|
22
|
+
* `serialize()` methods that allow a single instance to be reused for
|
|
23
|
+
* parsing/encoding multiple different values.
|
|
24
|
+
*
|
|
25
|
+
* @see https://remix.run/utils/cookies#cookie-api
|
|
26
|
+
*/
|
|
27
|
+
interface Cookie {
|
|
28
|
+
/**
|
|
29
|
+
* The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
|
|
30
|
+
*/
|
|
31
|
+
readonly name: string;
|
|
32
|
+
/**
|
|
33
|
+
* True if this cookie uses one or more secrets for verification.
|
|
34
|
+
*/
|
|
35
|
+
readonly isSigned: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The Date this cookie expires.
|
|
38
|
+
*
|
|
39
|
+
* Note: This is calculated at access time using `maxAge` when no `expires`
|
|
40
|
+
* option is provided to `createCookie()`.
|
|
41
|
+
*/
|
|
42
|
+
readonly expires?: Date;
|
|
43
|
+
/**
|
|
44
|
+
* Parses a raw `Cookie` header and returns the value of this cookie or
|
|
45
|
+
* `null` if it's not present.
|
|
46
|
+
*/
|
|
47
|
+
parse(cookieHeader: string | null, options?: CookieParseOptions$1): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Serializes the given value to a string and returns the `Set-Cookie`
|
|
50
|
+
* header.
|
|
51
|
+
*/
|
|
52
|
+
serialize(value: any, options?: CookieSerializeOptions$1): Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a logical container for managing a browser cookie from the server.
|
|
56
|
+
*/
|
|
57
|
+
declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
|
|
58
|
+
type IsCookieFunction = (object: any) => object is Cookie;
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if an object is a Remix cookie container.
|
|
61
|
+
*
|
|
62
|
+
* @see https://remix.run/utils/cookies#iscookie
|
|
63
|
+
*/
|
|
64
|
+
declare const isCookie: IsCookieFunction;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Cookie, CookieOptions, type CookieParseOptions$1 as CookieParseOptions, type CookieSerializeOptions$1 as CookieSerializeOptions, CookieSignatureOptions, IsCookieFunction, createCookie, isCookie };
|
|
@@ -0,0 +1,139 @@
|
|
|
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 { warnOnce } from "./warnings.js";
|
|
12
|
+
import { sign, unsign } from "./crypto.js";
|
|
13
|
+
import { parse, serialize } from "cookie-es";
|
|
14
|
+
//#region lib/server-runtime/cookies.ts
|
|
15
|
+
/**
|
|
16
|
+
* Creates a logical container for managing a browser cookie from the server.
|
|
17
|
+
*/
|
|
18
|
+
const createCookie = (name, cookieOptions = {}) => {
|
|
19
|
+
let { secrets = [], ...options } = {
|
|
20
|
+
path: "/",
|
|
21
|
+
sameSite: "lax",
|
|
22
|
+
...cookieOptions
|
|
23
|
+
};
|
|
24
|
+
warnOnceAboutExpiresCookie(name, options.expires);
|
|
25
|
+
return {
|
|
26
|
+
get name() {
|
|
27
|
+
return name;
|
|
28
|
+
},
|
|
29
|
+
get isSigned() {
|
|
30
|
+
return secrets.length > 0;
|
|
31
|
+
},
|
|
32
|
+
get expires() {
|
|
33
|
+
return typeof options.maxAge !== "undefined" ? new Date(Date.now() + options.maxAge * 1e3) : options.expires;
|
|
34
|
+
},
|
|
35
|
+
async parse(cookieHeader, parseOptions) {
|
|
36
|
+
if (!cookieHeader) return null;
|
|
37
|
+
let cookies = parse(cookieHeader, {
|
|
38
|
+
...options,
|
|
39
|
+
...parseOptions
|
|
40
|
+
});
|
|
41
|
+
if (name in cookies) {
|
|
42
|
+
let value = cookies[name];
|
|
43
|
+
if (typeof value === "string" && value !== "") return await decodeCookieValue(value, secrets);
|
|
44
|
+
else return "";
|
|
45
|
+
} else return null;
|
|
46
|
+
},
|
|
47
|
+
async serialize(value, serializeOptions) {
|
|
48
|
+
return serialize(name, value === "" ? "" : await encodeCookieValue(value, secrets), {
|
|
49
|
+
...options,
|
|
50
|
+
...serializeOptions
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if an object is a Remix cookie container.
|
|
57
|
+
*
|
|
58
|
+
* @see https://remix.run/utils/cookies#iscookie
|
|
59
|
+
*/
|
|
60
|
+
const isCookie = (object) => {
|
|
61
|
+
return object != null && typeof object.name === "string" && typeof object.isSigned === "boolean" && typeof object.parse === "function" && typeof object.serialize === "function";
|
|
62
|
+
};
|
|
63
|
+
async function encodeCookieValue(value, secrets) {
|
|
64
|
+
let encoded = encodeData(value);
|
|
65
|
+
if (secrets.length > 0) encoded = await sign(encoded, secrets[0]);
|
|
66
|
+
return encoded;
|
|
67
|
+
}
|
|
68
|
+
async function decodeCookieValue(value, secrets) {
|
|
69
|
+
if (secrets.length > 0) {
|
|
70
|
+
for (let secret of secrets) {
|
|
71
|
+
let unsignedValue = await unsign(value, secret);
|
|
72
|
+
if (unsignedValue !== false) return decodeData(unsignedValue);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return decodeData(value);
|
|
77
|
+
}
|
|
78
|
+
function encodeData(value) {
|
|
79
|
+
return btoa(myUnescape(encodeURIComponent(JSON.stringify(value))));
|
|
80
|
+
}
|
|
81
|
+
function decodeData(value) {
|
|
82
|
+
try {
|
|
83
|
+
return JSON.parse(decodeURIComponent(myEscape(atob(value))));
|
|
84
|
+
} catch (e) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function myEscape(value) {
|
|
89
|
+
let str = value.toString();
|
|
90
|
+
let result = "";
|
|
91
|
+
let index = 0;
|
|
92
|
+
let chr, code;
|
|
93
|
+
while (index < str.length) {
|
|
94
|
+
chr = str.charAt(index++);
|
|
95
|
+
if (/[\w*+\-./@]/.exec(chr)) result += chr;
|
|
96
|
+
else {
|
|
97
|
+
code = chr.charCodeAt(0);
|
|
98
|
+
if (code < 256) result += "%" + hex(code, 2);
|
|
99
|
+
else result += "%u" + hex(code, 4).toUpperCase();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
function hex(code, length) {
|
|
105
|
+
let result = code.toString(16);
|
|
106
|
+
while (result.length < length) result = "0" + result;
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function myUnescape(value) {
|
|
110
|
+
let str = value.toString();
|
|
111
|
+
let result = "";
|
|
112
|
+
let index = 0;
|
|
113
|
+
let chr, part;
|
|
114
|
+
while (index < str.length) {
|
|
115
|
+
chr = str.charAt(index++);
|
|
116
|
+
if (chr === "%") if (str.charAt(index) === "u") {
|
|
117
|
+
part = str.slice(index + 1, index + 5);
|
|
118
|
+
if (/^[\da-f]{4}$/i.exec(part)) {
|
|
119
|
+
result += String.fromCharCode(parseInt(part, 16));
|
|
120
|
+
index += 5;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
part = str.slice(index, index + 2);
|
|
125
|
+
if (/^[\da-f]{2}$/i.exec(part)) {
|
|
126
|
+
result += String.fromCharCode(parseInt(part, 16));
|
|
127
|
+
index += 2;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
result += chr;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
function warnOnceAboutExpiresCookie(name, expires) {
|
|
136
|
+
warnOnce(!expires, `The "${name}" cookie has an "expires" property set. This will cause the expires value to not be updated when the session is committed. Instead, you should set the expires value when serializing the cookie. You can use \`commitSession(session, { expires })\` if using a session storage object, or \`cookie.serialize("value", { expires })\` if you're using the cookie directly.`);
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { createCookie, isCookie };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#region lib/server-runtime/crypto.ts
|
|
12
|
+
const encoder = /* @__PURE__ */ new TextEncoder();
|
|
13
|
+
const sign = async (value, secret) => {
|
|
14
|
+
let data = encoder.encode(value);
|
|
15
|
+
let key = await createKey(secret, ["sign"]);
|
|
16
|
+
let signature = await crypto.subtle.sign("HMAC", key, data);
|
|
17
|
+
let hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(/=+$/, "");
|
|
18
|
+
return value + "." + hash;
|
|
19
|
+
};
|
|
20
|
+
const unsign = async (cookie, secret) => {
|
|
21
|
+
let index = cookie.lastIndexOf(".");
|
|
22
|
+
let value = cookie.slice(0, index);
|
|
23
|
+
let hash = cookie.slice(index + 1);
|
|
24
|
+
let data = encoder.encode(value);
|
|
25
|
+
let key = await createKey(secret, ["verify"]);
|
|
26
|
+
try {
|
|
27
|
+
let signature = byteStringToUint8Array(atob(hash));
|
|
28
|
+
return await crypto.subtle.verify("HMAC", key, signature, data) ? value : false;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const createKey = async (secret, usages) => crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
34
|
+
name: "HMAC",
|
|
35
|
+
hash: "SHA-256"
|
|
36
|
+
}, false, usages);
|
|
37
|
+
function byteStringToUint8Array(byteString) {
|
|
38
|
+
let array = new Uint8Array(byteString.length);
|
|
39
|
+
for (let i = 0; i < byteString.length; i++) array[i] = byteString.charCodeAt(i);
|
|
40
|
+
return array;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { sign, unsign };
|