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,74 @@
|
|
|
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 { redirect, redirectDocument, replace } from "../router/utils.js";
|
|
12
|
+
import { SingleFetchRedirectSymbol, decodeViaTurboStream } from "../dom/ssr/single-fetch.js";
|
|
13
|
+
import invariant from "./invariant.js";
|
|
14
|
+
import { callRouteHandler } from "./data.js";
|
|
15
|
+
import { getBuildTimeHeader } from "./dev.js";
|
|
16
|
+
//#region lib/server-runtime/routes.ts
|
|
17
|
+
function groupRoutesByParentId(manifest) {
|
|
18
|
+
let routes = {};
|
|
19
|
+
Object.values(manifest).forEach((route) => {
|
|
20
|
+
if (route) {
|
|
21
|
+
let parentId = route.parentId || "";
|
|
22
|
+
if (!routes[parentId]) routes[parentId] = [];
|
|
23
|
+
routes[parentId].push(route);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return routes;
|
|
27
|
+
}
|
|
28
|
+
function createStaticHandlerDataRoutes(manifest, parentId = "", routesByParentId = groupRoutesByParentId(manifest)) {
|
|
29
|
+
return (routesByParentId[parentId] || []).map((route) => {
|
|
30
|
+
let commonRoute = {
|
|
31
|
+
id: route.id,
|
|
32
|
+
path: route.path,
|
|
33
|
+
middleware: route.module.middleware,
|
|
34
|
+
loader: route.module.loader ? async (args) => {
|
|
35
|
+
let preRenderedData = getBuildTimeHeader(args.request, "X-React-Router-Prerender-Data");
|
|
36
|
+
if (preRenderedData != null) {
|
|
37
|
+
let encoded = preRenderedData ? decodeURI(preRenderedData) : preRenderedData;
|
|
38
|
+
invariant(encoded, "Missing prerendered data for route");
|
|
39
|
+
let uint8array = new TextEncoder().encode(encoded);
|
|
40
|
+
let data = (await decodeViaTurboStream(new ReadableStream({ start(controller) {
|
|
41
|
+
controller.enqueue(uint8array);
|
|
42
|
+
controller.close();
|
|
43
|
+
} }), global)).value;
|
|
44
|
+
if (data && SingleFetchRedirectSymbol in data) {
|
|
45
|
+
let result = data[SingleFetchRedirectSymbol];
|
|
46
|
+
let init = { status: result.status };
|
|
47
|
+
if (result.reload) throw redirectDocument(result.redirect, init);
|
|
48
|
+
else if (result.replace) throw replace(result.redirect, init);
|
|
49
|
+
else throw redirect(result.redirect, init);
|
|
50
|
+
} else {
|
|
51
|
+
invariant(data && route.id in data, "Unable to decode prerendered data");
|
|
52
|
+
let result = data[route.id];
|
|
53
|
+
invariant("data" in result, "Unable to process prerendered data");
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return await callRouteHandler(route.module.loader, args);
|
|
58
|
+
} : void 0,
|
|
59
|
+
action: route.module.action ? (args) => callRouteHandler(route.module.action, args) : void 0,
|
|
60
|
+
ErrorBoundary: route.id === "root" || route.module.ErrorBoundary != null ? () => null : void 0,
|
|
61
|
+
handle: route.module.handle
|
|
62
|
+
};
|
|
63
|
+
return route.index ? {
|
|
64
|
+
index: true,
|
|
65
|
+
...commonRoute
|
|
66
|
+
} : {
|
|
67
|
+
caseSensitive: route.caseSensitive,
|
|
68
|
+
children: createStaticHandlerDataRoutes(manifest, route.id, routesByParentId),
|
|
69
|
+
...commonRoute
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createStaticHandlerDataRoutes };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import { RouterContextProvider } from "../router/utils.js";
|
|
3
|
+
import { ServerBuild } from "./build.js";
|
|
4
|
+
|
|
5
|
+
//#region lib/server-runtime/server.d.ts
|
|
6
|
+
type RequestHandler = (request: Request, loadContext?: RouterContextProvider) => Promise<Response>;
|
|
7
|
+
type CreateRequestHandlerFunction = (build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>), mode?: string) => RequestHandler;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a request handler for a React Router server build.
|
|
10
|
+
*
|
|
11
|
+
* This is a low-level API used by server adapters to translate incoming
|
|
12
|
+
* requests into React Router responses.
|
|
13
|
+
*
|
|
14
|
+
* @category Utils
|
|
15
|
+
* @param build The server build, or a function that resolves to the server
|
|
16
|
+
* build, used to handle requests.
|
|
17
|
+
* @param mode The mode in which the server build is running.
|
|
18
|
+
* @returns A request handler that returns a response for each incoming request.
|
|
19
|
+
*/
|
|
20
|
+
declare const createRequestHandler: CreateRequestHandlerFunction;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { CreateRequestHandlerFunction, RequestHandler, createRequestHandler };
|
|
@@ -0,0 +1,364 @@
|
|
|
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 { ErrorResponseImpl, RouterContextProvider, createDataFunctionUrl, defaultMapRouteProperties, getRoutePattern, isRouteErrorResponse, removeTrailingSlash, stripBasename } from "../router/utils.js";
|
|
12
|
+
import { instrumentHandler, instrumentationResultMetaContext } from "../router/instrumentation.js";
|
|
13
|
+
import { createStaticHandler, getStaticContextFromError, isMutationMethod, isRedirectResponse, isResponse } from "../router/router.js";
|
|
14
|
+
import { getManifestPath } from "../dom/ssr/fog-of-war.js";
|
|
15
|
+
import { createEntryRouteModules } from "./entry.js";
|
|
16
|
+
import { isServerMode } from "./mode.js";
|
|
17
|
+
import { sanitizeErrors, serializeError } from "./errors.js";
|
|
18
|
+
import { matchServerRoutes } from "./routeMatching.js";
|
|
19
|
+
import { getBuildTimeHeader, getDevServerHooks } from "./dev.js";
|
|
20
|
+
import { createStaticHandlerDataRoutes } from "./routes.js";
|
|
21
|
+
import { createServerHandoffString } from "./serverHandoff.js";
|
|
22
|
+
import { getDocumentHeaders } from "./headers.js";
|
|
23
|
+
import { throwIfPotentialCSRFAttack } from "../actions.js";
|
|
24
|
+
import { getNormalizedPath } from "./urls.js";
|
|
25
|
+
import { SERVER_NO_BODY_STATUS_CODES, encodeViaTurboStream, generateSingleFetchRedirectResponse, singleFetchAction, singleFetchLoaders } from "./single-fetch.js";
|
|
26
|
+
//#region lib/server-runtime/server.ts
|
|
27
|
+
function derive(build, mode) {
|
|
28
|
+
let dataRoutes = createStaticHandlerDataRoutes(build.routes);
|
|
29
|
+
let serverMode = isServerMode(mode) ? mode : "production";
|
|
30
|
+
let staticHandler = createStaticHandler(dataRoutes, {
|
|
31
|
+
basename: build.basename,
|
|
32
|
+
mapRouteProperties: defaultMapRouteProperties,
|
|
33
|
+
instrumentations: build.entry.module.instrumentations,
|
|
34
|
+
future: build.future
|
|
35
|
+
});
|
|
36
|
+
let errorHandler = build.entry.module.handleError || ((error, { request }) => {
|
|
37
|
+
if (serverMode !== "test" && !request.signal.aborted) console.error(isRouteErrorResponse(error) && error.error ? error.error : error);
|
|
38
|
+
});
|
|
39
|
+
let requestHandlerInstrumentations = build.entry.module.instrumentations?.map((i) => i.handler).filter(Boolean);
|
|
40
|
+
let requestHandler = async (request, initialContext) => {
|
|
41
|
+
let params = {};
|
|
42
|
+
let loadContext;
|
|
43
|
+
let handleError = (error) => {
|
|
44
|
+
if (mode === "development") getDevServerHooks()?.processRequestError?.(error);
|
|
45
|
+
errorHandler(error, {
|
|
46
|
+
context: loadContext,
|
|
47
|
+
params,
|
|
48
|
+
request
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
if (initialContext && !(initialContext instanceof RouterContextProvider)) {
|
|
52
|
+
let error = /* @__PURE__ */ new Error("Invalid `context` value provided to `handleRequest`. You must return an instance of `RouterContextProvider` from your `getLoadContext` function.");
|
|
53
|
+
handleError(error);
|
|
54
|
+
return returnLastResortErrorResponse(error, serverMode);
|
|
55
|
+
}
|
|
56
|
+
loadContext = initialContext || new RouterContextProvider();
|
|
57
|
+
let requestUrl = new URL(request.url);
|
|
58
|
+
let normalizedPath = getNormalizedPath(request);
|
|
59
|
+
let normalizedPathname = normalizedPath.pathname;
|
|
60
|
+
let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
|
|
61
|
+
if (!build.ssr) {
|
|
62
|
+
let decodedPath = decodeURI(normalizedPathname);
|
|
63
|
+
if (build.basename && build.basename !== "/") {
|
|
64
|
+
let strippedPath = stripBasename(decodedPath, build.basename);
|
|
65
|
+
if (strippedPath == null) {
|
|
66
|
+
errorHandler(new ErrorResponseImpl(404, "Not Found", `Refusing to prerender the \`${decodedPath}\` path because it does not start with the basename \`${build.basename}\``), {
|
|
67
|
+
context: loadContext,
|
|
68
|
+
params,
|
|
69
|
+
request
|
|
70
|
+
});
|
|
71
|
+
return new Response("Not Found", {
|
|
72
|
+
status: 404,
|
|
73
|
+
statusText: "Not Found"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
decodedPath = strippedPath;
|
|
77
|
+
}
|
|
78
|
+
if (build.prerender.length === 0) isSpaMode = true;
|
|
79
|
+
else if (!build.prerender.some((p) => removeTrailingSlash(p) === removeTrailingSlash(decodedPath))) if (requestUrl.pathname.endsWith(".data")) {
|
|
80
|
+
errorHandler(new ErrorResponseImpl(404, "Not Found", `Refusing to SSR the path \`${decodedPath}\` because \`ssr:false\` is set and the path is not included in the \`prerender\` config, so in production the path will be a 404.`), {
|
|
81
|
+
context: loadContext,
|
|
82
|
+
params,
|
|
83
|
+
request
|
|
84
|
+
});
|
|
85
|
+
return new Response("Not Found", {
|
|
86
|
+
status: 404,
|
|
87
|
+
statusText: "Not Found"
|
|
88
|
+
});
|
|
89
|
+
} else isSpaMode = true;
|
|
90
|
+
}
|
|
91
|
+
let manifestUrl = getManifestPath(build.routeDiscovery.manifestPath, build.basename);
|
|
92
|
+
if (build.routeDiscovery.mode === "lazy" && requestUrl.pathname === manifestUrl) try {
|
|
93
|
+
return await handleManifestRequest(build, staticHandler.dataRoutes, staticHandler._internalRouteBranches, requestUrl);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
handleError(e);
|
|
96
|
+
return new Response("Unknown Server Error", { status: 500 });
|
|
97
|
+
}
|
|
98
|
+
let matches = matchServerRoutes(build.routes, staticHandler.dataRoutes, staticHandler._internalRouteBranches, normalizedPathname, build.basename);
|
|
99
|
+
if (matches && matches.length > 0) Object.assign(params, matches[0].params);
|
|
100
|
+
if (requestHandlerInstrumentations?.length) loadContext.set(instrumentationResultMetaContext, {
|
|
101
|
+
url: createDataFunctionUrl(request, normalizedPath),
|
|
102
|
+
pattern: matches ? getRoutePattern(matches) : "",
|
|
103
|
+
params: matches?.[0]?.params ? { ...matches[0].params } : {}
|
|
104
|
+
});
|
|
105
|
+
let response;
|
|
106
|
+
if (requestUrl.pathname.endsWith(".data")) {
|
|
107
|
+
response = await handleSingleFetchRequest(serverMode, build, staticHandler, request, loadContext, handleError);
|
|
108
|
+
if (isRedirectResponse(response)) response = generateSingleFetchRedirectResponse(response, request, build, serverMode);
|
|
109
|
+
if (build.entry.module.handleDataRequest) {
|
|
110
|
+
response = await build.entry.module.handleDataRequest(response, {
|
|
111
|
+
context: loadContext,
|
|
112
|
+
params: matches ? matches[0].params : {},
|
|
113
|
+
request
|
|
114
|
+
});
|
|
115
|
+
if (isRedirectResponse(response)) response = generateSingleFetchRedirectResponse(response, request, build, serverMode);
|
|
116
|
+
}
|
|
117
|
+
} else if (!isSpaMode && matches && matches[matches.length - 1].route.module.default == null && matches[matches.length - 1].route.module.ErrorBoundary == null) response = await handleResourceRequest(serverMode, build, staticHandler, matches.slice(-1)[0].route.id, request, loadContext, handleError);
|
|
118
|
+
else {
|
|
119
|
+
let { pathname } = requestUrl;
|
|
120
|
+
let criticalCss = void 0;
|
|
121
|
+
if (build.unstable_getCriticalCss) criticalCss = await build.unstable_getCriticalCss({ pathname });
|
|
122
|
+
else if (mode === "development" && getDevServerHooks()?.getCriticalCss) criticalCss = await getDevServerHooks()?.getCriticalCss?.(pathname);
|
|
123
|
+
response = await handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss);
|
|
124
|
+
}
|
|
125
|
+
if (request.method === "HEAD") return new Response(null, {
|
|
126
|
+
headers: response.headers,
|
|
127
|
+
status: response.status,
|
|
128
|
+
statusText: response.statusText
|
|
129
|
+
});
|
|
130
|
+
return response;
|
|
131
|
+
};
|
|
132
|
+
if (requestHandlerInstrumentations?.length) requestHandler = instrumentHandler(requestHandler, requestHandlerInstrumentations);
|
|
133
|
+
return {
|
|
134
|
+
serverMode,
|
|
135
|
+
staticHandler,
|
|
136
|
+
errorHandler,
|
|
137
|
+
requestHandler
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Creates a request handler for a React Router server build.
|
|
142
|
+
*
|
|
143
|
+
* This is a low-level API used by server adapters to translate incoming
|
|
144
|
+
* requests into React Router responses.
|
|
145
|
+
*
|
|
146
|
+
* @category Utils
|
|
147
|
+
* @param build The server build, or a function that resolves to the server
|
|
148
|
+
* build, used to handle requests.
|
|
149
|
+
* @param mode The mode in which the server build is running.
|
|
150
|
+
* @returns A request handler that returns a response for each incoming request.
|
|
151
|
+
*/
|
|
152
|
+
const createRequestHandler = (build, mode) => {
|
|
153
|
+
let _build;
|
|
154
|
+
let serverMode;
|
|
155
|
+
let staticHandler;
|
|
156
|
+
let errorHandler;
|
|
157
|
+
let _requestHandler;
|
|
158
|
+
return async function requestHandler(request, initialContext) {
|
|
159
|
+
_build = typeof build === "function" ? await build() : build;
|
|
160
|
+
if (typeof build === "function") {
|
|
161
|
+
let derived = derive(_build, mode);
|
|
162
|
+
serverMode = derived.serverMode;
|
|
163
|
+
staticHandler = derived.staticHandler;
|
|
164
|
+
errorHandler = derived.errorHandler;
|
|
165
|
+
_requestHandler = derived.requestHandler;
|
|
166
|
+
} else if (!serverMode || !staticHandler || !errorHandler || !_requestHandler) {
|
|
167
|
+
let derived = derive(_build, mode);
|
|
168
|
+
serverMode = derived.serverMode;
|
|
169
|
+
staticHandler = derived.staticHandler;
|
|
170
|
+
errorHandler = derived.errorHandler;
|
|
171
|
+
_requestHandler = derived.requestHandler;
|
|
172
|
+
}
|
|
173
|
+
return _requestHandler(request, initialContext);
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
async function handleManifestRequest(build, dataRoutes, branches, url) {
|
|
177
|
+
if (url.toString().length > 7680) return new Response(null, {
|
|
178
|
+
statusText: "Bad Request",
|
|
179
|
+
status: 400
|
|
180
|
+
});
|
|
181
|
+
if (build.assets.version !== url.searchParams.get("version")) return new Response(null, {
|
|
182
|
+
status: 204,
|
|
183
|
+
headers: { "X-Remix-Reload-Document": "true" }
|
|
184
|
+
});
|
|
185
|
+
let patches = {};
|
|
186
|
+
if (url.searchParams.has("paths")) {
|
|
187
|
+
let pathParam = url.searchParams.get("paths") || "";
|
|
188
|
+
let paths = new Set(pathParam.split(",").filter(Boolean));
|
|
189
|
+
for (let path of paths) {
|
|
190
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
191
|
+
let matches = matchServerRoutes(build.routes, dataRoutes, branches, path, build.basename);
|
|
192
|
+
if (matches) for (let match of matches) {
|
|
193
|
+
let routeId = match.route.id;
|
|
194
|
+
let route = build.assets.routes[routeId];
|
|
195
|
+
if (route) patches[routeId] = route;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return Response.json(patches, { headers: { "Cache-Control": "public, max-age=31536000, immutable" } });
|
|
199
|
+
}
|
|
200
|
+
return new Response("Invalid Request", { status: 400 });
|
|
201
|
+
}
|
|
202
|
+
async function handleSingleFetchRequest(serverMode, build, staticHandler, request, loadContext, handleError) {
|
|
203
|
+
return isMutationMethod(request.method) ? await singleFetchAction(build, serverMode, staticHandler, request, loadContext, handleError) : await singleFetchLoaders(build, serverMode, staticHandler, request, loadContext, handleError);
|
|
204
|
+
}
|
|
205
|
+
async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss) {
|
|
206
|
+
try {
|
|
207
|
+
if (isMutationMethod(request.method)) try {
|
|
208
|
+
throwIfPotentialCSRFAttack(request, Array.isArray(build.allowedActionOrigins) ? build.allowedActionOrigins : []);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
handleError(e);
|
|
211
|
+
return new Response("Bad Request", { status: 400 });
|
|
212
|
+
}
|
|
213
|
+
let result = await staticHandler.query(request, {
|
|
214
|
+
requestContext: loadContext,
|
|
215
|
+
generateMiddlewareResponse: async (query) => {
|
|
216
|
+
try {
|
|
217
|
+
let innerResult = await query(request);
|
|
218
|
+
if (!isResponse(innerResult)) innerResult = await renderHtml(innerResult, isSpaMode);
|
|
219
|
+
return innerResult;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
handleError(error);
|
|
222
|
+
return new Response(null, { status: 500 });
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
normalizePath: (r) => getNormalizedPath(r)
|
|
226
|
+
});
|
|
227
|
+
if (!isResponse(result)) result = await renderHtml(result, isSpaMode);
|
|
228
|
+
return result;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
handleError(error);
|
|
231
|
+
return new Response(null, { status: 500 });
|
|
232
|
+
}
|
|
233
|
+
async function renderHtml(context, isSpaMode) {
|
|
234
|
+
let headers = getDocumentHeaders(context, build);
|
|
235
|
+
if (SERVER_NO_BODY_STATUS_CODES.has(context.statusCode)) return new Response(null, {
|
|
236
|
+
status: context.statusCode,
|
|
237
|
+
headers
|
|
238
|
+
});
|
|
239
|
+
if (context.errors) {
|
|
240
|
+
Object.values(context.errors).forEach((err) => {
|
|
241
|
+
if (!isRouteErrorResponse(err) || err.error) handleError(err);
|
|
242
|
+
});
|
|
243
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
244
|
+
}
|
|
245
|
+
let state = {
|
|
246
|
+
loaderData: context.loaderData,
|
|
247
|
+
actionData: context.actionData,
|
|
248
|
+
errors: context.errors
|
|
249
|
+
};
|
|
250
|
+
let baseServerHandoff = {
|
|
251
|
+
basename: build.basename,
|
|
252
|
+
future: build.future,
|
|
253
|
+
routeDiscovery: build.routeDiscovery,
|
|
254
|
+
ssr: build.ssr,
|
|
255
|
+
isSpaMode
|
|
256
|
+
};
|
|
257
|
+
let entryContext = {
|
|
258
|
+
manifest: build.assets,
|
|
259
|
+
branches: staticHandler._internalRouteBranches,
|
|
260
|
+
routeModules: createEntryRouteModules(build.routes),
|
|
261
|
+
staticHandlerContext: context,
|
|
262
|
+
criticalCss,
|
|
263
|
+
serverHandoffString: createServerHandoffString({
|
|
264
|
+
...baseServerHandoff,
|
|
265
|
+
criticalCss
|
|
266
|
+
}),
|
|
267
|
+
serverHandoffStream: encodeViaTurboStream(state, request.signal, build.entry.module.streamTimeout, serverMode),
|
|
268
|
+
renderMeta: {},
|
|
269
|
+
future: build.future,
|
|
270
|
+
ssr: build.ssr,
|
|
271
|
+
routeDiscovery: build.routeDiscovery,
|
|
272
|
+
isSpaMode,
|
|
273
|
+
serializeError: (err) => serializeError(err, serverMode)
|
|
274
|
+
};
|
|
275
|
+
let handleDocumentRequestFunction = build.entry.module.default;
|
|
276
|
+
try {
|
|
277
|
+
return await handleDocumentRequestFunction(request, context.statusCode, headers, entryContext, loadContext);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
handleError(error);
|
|
280
|
+
let errorForSecondRender = error;
|
|
281
|
+
if (isResponse(error)) try {
|
|
282
|
+
let data = await unwrapResponse(error);
|
|
283
|
+
errorForSecondRender = new ErrorResponseImpl(error.status, error.statusText, data);
|
|
284
|
+
} catch (e) {}
|
|
285
|
+
context = getStaticContextFromError(staticHandler.dataRoutes, context, errorForSecondRender);
|
|
286
|
+
if (context.errors) context.errors = sanitizeErrors(context.errors, serverMode);
|
|
287
|
+
let state = {
|
|
288
|
+
loaderData: context.loaderData,
|
|
289
|
+
actionData: context.actionData,
|
|
290
|
+
errors: context.errors
|
|
291
|
+
};
|
|
292
|
+
entryContext = {
|
|
293
|
+
...entryContext,
|
|
294
|
+
staticHandlerContext: context,
|
|
295
|
+
serverHandoffString: createServerHandoffString(baseServerHandoff),
|
|
296
|
+
serverHandoffStream: encodeViaTurboStream(state, request.signal, build.entry.module.streamTimeout, serverMode),
|
|
297
|
+
renderMeta: {}
|
|
298
|
+
};
|
|
299
|
+
try {
|
|
300
|
+
return await handleDocumentRequestFunction(request, context.statusCode, headers, entryContext, loadContext);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
handleError(error);
|
|
303
|
+
return returnLastResortErrorResponse(error, serverMode);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function handleResourceRequest(serverMode, build, staticHandler, routeId, request, loadContext, handleError) {
|
|
309
|
+
try {
|
|
310
|
+
return handleQueryRouteResult(await staticHandler.queryRoute(request, {
|
|
311
|
+
routeId,
|
|
312
|
+
requestContext: loadContext,
|
|
313
|
+
generateMiddlewareResponse: async (queryRoute) => {
|
|
314
|
+
try {
|
|
315
|
+
return handleQueryRouteResult(await queryRoute(request));
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return handleQueryRouteError(error);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
normalizePath: (r) => getNormalizedPath(r)
|
|
321
|
+
}));
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return handleQueryRouteError(error);
|
|
324
|
+
}
|
|
325
|
+
function handleQueryRouteResult(result) {
|
|
326
|
+
if (isResponse(result)) return result;
|
|
327
|
+
if (typeof result === "string") return new Response(result);
|
|
328
|
+
return Response.json(result);
|
|
329
|
+
}
|
|
330
|
+
function handleQueryRouteError(error) {
|
|
331
|
+
if (isResponse(error)) return error;
|
|
332
|
+
if (isRouteErrorResponse(error)) {
|
|
333
|
+
handleError(error);
|
|
334
|
+
return errorResponseToJson(error, serverMode);
|
|
335
|
+
}
|
|
336
|
+
if (error instanceof Error && error.message === "Expected a response from queryRoute") {
|
|
337
|
+
let newError = /* @__PURE__ */ new Error("Expected a Response to be returned from resource route handler");
|
|
338
|
+
handleError(newError);
|
|
339
|
+
return returnLastResortErrorResponse(newError, serverMode);
|
|
340
|
+
}
|
|
341
|
+
handleError(error);
|
|
342
|
+
return returnLastResortErrorResponse(error, serverMode);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function errorResponseToJson(errorResponse, serverMode) {
|
|
346
|
+
return Response.json(serializeError(errorResponse.error || /* @__PURE__ */ new Error("Unexpected Server Error"), serverMode), {
|
|
347
|
+
status: errorResponse.status,
|
|
348
|
+
statusText: errorResponse.statusText
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function returnLastResortErrorResponse(error, serverMode) {
|
|
352
|
+
let message = "Unexpected Server Error";
|
|
353
|
+
if (serverMode !== "production") message += `\n\n${String(error)}`;
|
|
354
|
+
return new Response(message, {
|
|
355
|
+
status: 500,
|
|
356
|
+
headers: { "Content-Type": "text/plain" }
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function unwrapResponse(response) {
|
|
360
|
+
let contentType = response.headers.get("Content-Type");
|
|
361
|
+
return contentType && /\bapplication\/json\b/.test(contentType) ? response.body == null ? null : response.json() : response.text();
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
export { createRequestHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { escapeHtml } from "../dom/ssr/markup.js";
|
|
12
|
+
//#region lib/server-runtime/serverHandoff.ts
|
|
13
|
+
function createServerHandoffString(serverHandoff) {
|
|
14
|
+
return escapeHtml(JSON.stringify(serverHandoff));
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createServerHandoffString };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage } from "../sessions.js";
|
|
3
|
+
|
|
4
|
+
//#region lib/server-runtime/sessions/cookieStorage.d.ts
|
|
5
|
+
interface CookieSessionStorageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The Cookie used to store the session data on the client, or options used
|
|
8
|
+
* to automatically create one.
|
|
9
|
+
*/
|
|
10
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates and returns a SessionStorage object that stores all session data
|
|
14
|
+
* directly in the session cookie itself.
|
|
15
|
+
*
|
|
16
|
+
* This has the advantage that no database or other backend services are
|
|
17
|
+
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
18
|
+
* also has the limitation that serialized session data may not exceed the
|
|
19
|
+
* browser's maximum cookie size. Trade-offs!
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @category Utils
|
|
23
|
+
* @mode framework
|
|
24
|
+
* @mode data
|
|
25
|
+
* @param options Options for creating the cookie-backed session storage.
|
|
26
|
+
* @returns A {@link SessionStorage} object that stores all session data in its
|
|
27
|
+
* cookie.
|
|
28
|
+
*/
|
|
29
|
+
declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({
|
|
30
|
+
cookie: cookieArg
|
|
31
|
+
}?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createCookieSessionStorage };
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { createCookie, isCookie } from "../cookies.js";
|
|
12
|
+
import { createSession, warnOnceAboutSigningSessionCookie } from "../sessions.js";
|
|
13
|
+
//#region lib/server-runtime/sessions/cookieStorage.ts
|
|
14
|
+
/**
|
|
15
|
+
* Creates and returns a SessionStorage object that stores all session data
|
|
16
|
+
* directly in the session cookie itself.
|
|
17
|
+
*
|
|
18
|
+
* This has the advantage that no database or other backend services are
|
|
19
|
+
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
20
|
+
* also has the limitation that serialized session data may not exceed the
|
|
21
|
+
* browser's maximum cookie size. Trade-offs!
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @category Utils
|
|
25
|
+
* @mode framework
|
|
26
|
+
* @mode data
|
|
27
|
+
* @param options Options for creating the cookie-backed session storage.
|
|
28
|
+
* @returns A {@link SessionStorage} object that stores all session data in its
|
|
29
|
+
* cookie.
|
|
30
|
+
*/
|
|
31
|
+
function createCookieSessionStorage({ cookie: cookieArg } = {}) {
|
|
32
|
+
let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
|
|
33
|
+
warnOnceAboutSigningSessionCookie(cookie);
|
|
34
|
+
return {
|
|
35
|
+
async getSession(cookieHeader, options) {
|
|
36
|
+
return createSession(cookieHeader && await cookie.parse(cookieHeader, options) || {});
|
|
37
|
+
},
|
|
38
|
+
async commitSession(session, options) {
|
|
39
|
+
let serializedCookie = await cookie.serialize(session.data, options);
|
|
40
|
+
if (serializedCookie.length > 4096) throw new Error("Cookie length will exceed browser maximum. Length: " + serializedCookie.length);
|
|
41
|
+
return serializedCookie;
|
|
42
|
+
},
|
|
43
|
+
async destroySession(_session, options) {
|
|
44
|
+
return cookie.serialize("", {
|
|
45
|
+
...options,
|
|
46
|
+
maxAge: void 0,
|
|
47
|
+
expires: /* @__PURE__ */ new Date(0)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { createCookieSessionStorage };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage } from "../sessions.js";
|
|
3
|
+
|
|
4
|
+
//#region lib/server-runtime/sessions/memoryStorage.d.ts
|
|
5
|
+
interface MemorySessionStorageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The Cookie used to store the session id on the client, or options used
|
|
8
|
+
* to automatically create one.
|
|
9
|
+
*/
|
|
10
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates and returns a simple in-memory SessionStorage object.
|
|
14
|
+
*
|
|
15
|
+
* Intended for local development and testing. It does not scale beyond a single
|
|
16
|
+
* process, and all session data is lost when the server process stops/restarts.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @category Utils
|
|
20
|
+
* @mode framework
|
|
21
|
+
* @mode data
|
|
22
|
+
* @param options Options for creating the in-memory session storage.
|
|
23
|
+
* @returns A {@link SessionStorage} object that stores session data in memory.
|
|
24
|
+
*/
|
|
25
|
+
declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({
|
|
26
|
+
cookie
|
|
27
|
+
}?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createMemorySessionStorage };
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { createSessionStorage } from "../sessions.js";
|
|
12
|
+
//#region lib/server-runtime/sessions/memoryStorage.ts
|
|
13
|
+
/**
|
|
14
|
+
* Creates and returns a simple in-memory SessionStorage object.
|
|
15
|
+
*
|
|
16
|
+
* Intended for local development and testing. It does not scale beyond a single
|
|
17
|
+
* process, and all session data is lost when the server process stops/restarts.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
* @category Utils
|
|
21
|
+
* @mode framework
|
|
22
|
+
* @mode data
|
|
23
|
+
* @param options Options for creating the in-memory session storage.
|
|
24
|
+
* @returns A {@link SessionStorage} object that stores session data in memory.
|
|
25
|
+
*/
|
|
26
|
+
function createMemorySessionStorage({ cookie } = {}) {
|
|
27
|
+
let map = /* @__PURE__ */ new Map();
|
|
28
|
+
return createSessionStorage({
|
|
29
|
+
cookie,
|
|
30
|
+
async createData(data, expires) {
|
|
31
|
+
let id = crypto.randomUUID();
|
|
32
|
+
map.set(id, {
|
|
33
|
+
data,
|
|
34
|
+
expires
|
|
35
|
+
});
|
|
36
|
+
return id;
|
|
37
|
+
},
|
|
38
|
+
async readData(id) {
|
|
39
|
+
if (map.has(id)) {
|
|
40
|
+
let { data, expires } = map.get(id);
|
|
41
|
+
if (!expires || expires > /* @__PURE__ */ new Date()) return data;
|
|
42
|
+
if (expires) map.delete(id);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
},
|
|
46
|
+
async updateData(id, data, expires) {
|
|
47
|
+
map.set(id, {
|
|
48
|
+
data,
|
|
49
|
+
expires
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async deleteData(id) {
|
|
53
|
+
map.delete(id);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createMemorySessionStorage };
|