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,174 @@
|
|
|
1
|
+
|
|
2
|
+
import { Cookie, CookieOptions } from "./cookies.js";
|
|
3
|
+
import { CookieParseOptions, CookieSerializeOptions } from "cookie-es";
|
|
4
|
+
|
|
5
|
+
//#region lib/server-runtime/sessions.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* An object of name/value pairs to be used in the session.
|
|
8
|
+
*/
|
|
9
|
+
interface SessionData {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Session persists data across HTTP requests.
|
|
14
|
+
*
|
|
15
|
+
* @see https://reactrouter.com/explanation/sessions-and-cookies#sessions
|
|
16
|
+
*/
|
|
17
|
+
interface Session<Data = SessionData, FlashData = Data> {
|
|
18
|
+
/**
|
|
19
|
+
* A unique identifier for this session.
|
|
20
|
+
*
|
|
21
|
+
* Note: This will be the empty string for newly created sessions and
|
|
22
|
+
* sessions that are not backed by a database (i.e. cookie-based sessions).
|
|
23
|
+
*/
|
|
24
|
+
readonly id: string;
|
|
25
|
+
/**
|
|
26
|
+
* The raw data contained in this session.
|
|
27
|
+
*
|
|
28
|
+
* This is useful mostly for SessionStorage internally to access the raw
|
|
29
|
+
* session data to persist.
|
|
30
|
+
*/
|
|
31
|
+
readonly data: FlashSessionData<Data, FlashData>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns `true` if the session has a value for the given `name`, `false`
|
|
34
|
+
* otherwise.
|
|
35
|
+
*/
|
|
36
|
+
has(name: (keyof Data | keyof FlashData) & string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the value for the given `name` in this session.
|
|
39
|
+
*/
|
|
40
|
+
get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Sets a value in the session for the given `name`.
|
|
43
|
+
*/
|
|
44
|
+
set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Sets a value in the session that is only valid until the next `get()`.
|
|
47
|
+
* This can be useful for temporary values, like error messages.
|
|
48
|
+
*/
|
|
49
|
+
flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
|
|
50
|
+
/**
|
|
51
|
+
* Removes a value from the session.
|
|
52
|
+
*/
|
|
53
|
+
unset(name: keyof Data & string): void;
|
|
54
|
+
}
|
|
55
|
+
type FlashSessionData<Data, FlashData> = Partial<Data & { [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key] }>;
|
|
56
|
+
type FlashDataKey<Key extends string> = `__flash_${Key}__`;
|
|
57
|
+
type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new Session object.
|
|
60
|
+
*
|
|
61
|
+
* Note: This function is typically not invoked directly by application code.
|
|
62
|
+
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
63
|
+
*
|
|
64
|
+
* @category Utils
|
|
65
|
+
* @param initialData The initial data for the session.
|
|
66
|
+
* @param id The identifier for the session. Defaults to an empty string for a
|
|
67
|
+
* new session.
|
|
68
|
+
* @returns A new {@link Session} object.
|
|
69
|
+
*/
|
|
70
|
+
declare const createSession: CreateSessionFunction;
|
|
71
|
+
/**
|
|
72
|
+
* A function that determines whether a value is a React Router {@link Session}
|
|
73
|
+
* object.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
* @category Utils
|
|
77
|
+
* @mode framework
|
|
78
|
+
* @mode data
|
|
79
|
+
* @param object The value to check.
|
|
80
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
81
|
+
* otherwise, `false`.
|
|
82
|
+
*/
|
|
83
|
+
type IsSessionFunction = (object: any) => object is Session;
|
|
84
|
+
/**
|
|
85
|
+
* Returns `true` if a value is a React Router {@link Session} object.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
* @category Utils
|
|
89
|
+
* @mode framework
|
|
90
|
+
* @mode data
|
|
91
|
+
* @param object The value to check.
|
|
92
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
93
|
+
* otherwise, `false`.
|
|
94
|
+
*/
|
|
95
|
+
declare const isSession: IsSessionFunction;
|
|
96
|
+
/**
|
|
97
|
+
* SessionStorage stores session data between HTTP requests and knows how to
|
|
98
|
+
* parse and create cookies.
|
|
99
|
+
*
|
|
100
|
+
* A SessionStorage creates Session objects using a `Cookie` header as input.
|
|
101
|
+
* Then, later it generates the `Set-Cookie` header to be used in the response.
|
|
102
|
+
*/
|
|
103
|
+
interface SessionStorage<Data = SessionData, FlashData = Data> {
|
|
104
|
+
/**
|
|
105
|
+
* Parses a Cookie header from a HTTP request and returns the associated
|
|
106
|
+
* Session. If there is no session associated with the cookie, this will
|
|
107
|
+
* return a new Session with no data.
|
|
108
|
+
*/
|
|
109
|
+
getSession: (cookieHeader?: string | null, options?: CookieParseOptions) => Promise<Session<Data, FlashData>>;
|
|
110
|
+
/**
|
|
111
|
+
* Stores all data in the Session and returns the Set-Cookie header to be
|
|
112
|
+
* used in the HTTP response.
|
|
113
|
+
*/
|
|
114
|
+
commitSession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Deletes all data associated with the Session and returns the Set-Cookie
|
|
117
|
+
* header to be used in the HTTP response.
|
|
118
|
+
*/
|
|
119
|
+
destroySession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* SessionIdStorageStrategy is designed to allow anyone to easily build their
|
|
123
|
+
* own SessionStorage using `createSessionStorage(strategy)`.
|
|
124
|
+
*
|
|
125
|
+
* This strategy describes a common scenario where the session id is stored in
|
|
126
|
+
* a cookie but the actual session data is stored elsewhere, usually in a
|
|
127
|
+
* database or on disk. A set of create, read, update, and delete operations
|
|
128
|
+
* are provided for managing the session data.
|
|
129
|
+
*/
|
|
130
|
+
interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
|
|
131
|
+
/**
|
|
132
|
+
* The Cookie used to store the session id, or options used to automatically
|
|
133
|
+
* create one.
|
|
134
|
+
*/
|
|
135
|
+
cookie?: Cookie | (CookieOptions & {
|
|
136
|
+
name?: string;
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* Creates a new record with the given data and returns the session id.
|
|
140
|
+
*/
|
|
141
|
+
createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Returns data for a given session id, or `null` if there isn't any.
|
|
144
|
+
*/
|
|
145
|
+
readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
|
|
146
|
+
/**
|
|
147
|
+
* Updates data for the given session id.
|
|
148
|
+
*/
|
|
149
|
+
updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Deletes data for a given session id from the data store.
|
|
152
|
+
*/
|
|
153
|
+
deleteData: (id: string) => Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates a SessionStorage object using a SessionIdStorageStrategy.
|
|
157
|
+
*
|
|
158
|
+
* Note: This is a low-level API that should only be used if none of the
|
|
159
|
+
* existing session storage options meet your requirements.
|
|
160
|
+
*
|
|
161
|
+
* @category Utils
|
|
162
|
+
* @param strategy The strategy used to store session identifiers and data.
|
|
163
|
+
* @returns A {@link SessionStorage} object that persists session data using the
|
|
164
|
+
* provided strategy.
|
|
165
|
+
*/
|
|
166
|
+
declare function createSessionStorage<Data = SessionData, FlashData = Data>({
|
|
167
|
+
cookie: cookieArg,
|
|
168
|
+
createData,
|
|
169
|
+
readData,
|
|
170
|
+
updateData,
|
|
171
|
+
deleteData
|
|
172
|
+
}: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
|
|
173
|
+
//#endregion
|
|
174
|
+
export { FlashSessionData, IsSessionFunction, Session, SessionData, SessionIdStorageStrategy, SessionStorage, createSession, createSessionStorage, isSession };
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { warnOnce } from "./warnings.js";
|
|
12
|
+
import { createCookie, isCookie } from "./cookies.js";
|
|
13
|
+
//#region lib/server-runtime/sessions.ts
|
|
14
|
+
function flash(name) {
|
|
15
|
+
return `__flash_${name}__`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new Session object.
|
|
19
|
+
*
|
|
20
|
+
* Note: This function is typically not invoked directly by application code.
|
|
21
|
+
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
22
|
+
*
|
|
23
|
+
* @category Utils
|
|
24
|
+
* @param initialData The initial data for the session.
|
|
25
|
+
* @param id The identifier for the session. Defaults to an empty string for a
|
|
26
|
+
* new session.
|
|
27
|
+
* @returns A new {@link Session} object.
|
|
28
|
+
*/
|
|
29
|
+
const createSession = (initialData = {}, id = "") => {
|
|
30
|
+
let map = new Map(Object.entries(initialData));
|
|
31
|
+
return {
|
|
32
|
+
get id() {
|
|
33
|
+
return id;
|
|
34
|
+
},
|
|
35
|
+
get data() {
|
|
36
|
+
return Object.fromEntries(map);
|
|
37
|
+
},
|
|
38
|
+
has(name) {
|
|
39
|
+
return map.has(name) || map.has(flash(name));
|
|
40
|
+
},
|
|
41
|
+
get(name) {
|
|
42
|
+
if (map.has(name)) return map.get(name);
|
|
43
|
+
let flashName = flash(name);
|
|
44
|
+
if (map.has(flashName)) {
|
|
45
|
+
let value = map.get(flashName);
|
|
46
|
+
map.delete(flashName);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
set(name, value) {
|
|
51
|
+
map.set(name, value);
|
|
52
|
+
},
|
|
53
|
+
flash(name, value) {
|
|
54
|
+
map.set(flash(name), value);
|
|
55
|
+
},
|
|
56
|
+
unset(name) {
|
|
57
|
+
map.delete(name);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Returns `true` if a value is a React Router {@link Session} object.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
* @category Utils
|
|
66
|
+
* @mode framework
|
|
67
|
+
* @mode data
|
|
68
|
+
* @param object The value to check.
|
|
69
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
70
|
+
* otherwise, `false`.
|
|
71
|
+
*/
|
|
72
|
+
const isSession = (object) => {
|
|
73
|
+
return object != null && typeof object.id === "string" && typeof object.data !== "undefined" && typeof object.has === "function" && typeof object.get === "function" && typeof object.set === "function" && typeof object.flash === "function" && typeof object.unset === "function";
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Creates a SessionStorage object using a SessionIdStorageStrategy.
|
|
77
|
+
*
|
|
78
|
+
* Note: This is a low-level API that should only be used if none of the
|
|
79
|
+
* existing session storage options meet your requirements.
|
|
80
|
+
*
|
|
81
|
+
* @category Utils
|
|
82
|
+
* @param strategy The strategy used to store session identifiers and data.
|
|
83
|
+
* @returns A {@link SessionStorage} object that persists session data using the
|
|
84
|
+
* provided strategy.
|
|
85
|
+
*/
|
|
86
|
+
function createSessionStorage({ cookie: cookieArg, createData, readData, updateData, deleteData }) {
|
|
87
|
+
let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
|
|
88
|
+
warnOnceAboutSigningSessionCookie(cookie);
|
|
89
|
+
return {
|
|
90
|
+
async getSession(cookieHeader, options) {
|
|
91
|
+
let id = cookieHeader && await cookie.parse(cookieHeader, options);
|
|
92
|
+
return createSession(id && await readData(id) || {}, id || "");
|
|
93
|
+
},
|
|
94
|
+
async commitSession(session, options) {
|
|
95
|
+
let { id, data } = session;
|
|
96
|
+
let expires = options?.maxAge != null ? new Date(Date.now() + options.maxAge * 1e3) : options?.expires != null ? options.expires : cookie.expires;
|
|
97
|
+
if (id) await updateData(id, data, expires);
|
|
98
|
+
else id = await createData(data, expires);
|
|
99
|
+
return cookie.serialize(id, options);
|
|
100
|
+
},
|
|
101
|
+
async destroySession(session, options) {
|
|
102
|
+
await deleteData(session.id);
|
|
103
|
+
return cookie.serialize("", {
|
|
104
|
+
...options,
|
|
105
|
+
maxAge: void 0,
|
|
106
|
+
expires: /* @__PURE__ */ new Date(0)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function warnOnceAboutSigningSessionCookie(cookie) {
|
|
112
|
+
warnOnce(cookie.isSigned, `The "${cookie.name}" cookie is not signed, but session cookies should be signed to prevent tampering on the client before they are sent back to the server. See https://reactrouter.com/explanation/sessions-and-cookies#signing-cookies for more information.`);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
export { createSession, createSessionStorage, isSession, warnOnceAboutSigningSessionCookie };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
//#region lib/server-runtime/single-fetch.d.ts
|
|
3
|
+
type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
|
|
4
|
+
[key: PropertyKey]: Serializable;
|
|
5
|
+
} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { Serializable };
|
|
@@ -0,0 +1,215 @@
|
|
|
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, isRouteErrorResponse, stripBasename } from "../router/utils.js";
|
|
12
|
+
import { isRedirectStatusCode, isResponse } from "../router/router.js";
|
|
13
|
+
import { encode } from "../../vendor/turbo-stream-v2/turbo-stream.js";
|
|
14
|
+
import { NO_BODY_STATUS_CODES, SingleFetchRedirectSymbol } from "../dom/ssr/single-fetch.js";
|
|
15
|
+
import "./mode.js";
|
|
16
|
+
import { sanitizeError, sanitizeErrors } from "./errors.js";
|
|
17
|
+
import { getDocumentHeaders } from "./headers.js";
|
|
18
|
+
import { throwIfPotentialCSRFAttack } from "../actions.js";
|
|
19
|
+
import { getNormalizedPath } from "./urls.js";
|
|
20
|
+
//#region lib/server-runtime/single-fetch.ts
|
|
21
|
+
const SERVER_NO_BODY_STATUS_CODES = new Set([...NO_BODY_STATUS_CODES, 304]);
|
|
22
|
+
async function singleFetchAction(build, serverMode, staticHandler, request, loadContext, handleError) {
|
|
23
|
+
try {
|
|
24
|
+
try {
|
|
25
|
+
throwIfPotentialCSRFAttack(request, Array.isArray(build.allowedActionOrigins) ? build.allowedActionOrigins : []);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return handleQueryError(/* @__PURE__ */ new Error("Bad Request"), 400);
|
|
28
|
+
}
|
|
29
|
+
return handleQueryResult(await staticHandler.query(request, {
|
|
30
|
+
requestContext: loadContext,
|
|
31
|
+
skipLoaderErrorBubbling: true,
|
|
32
|
+
skipRevalidation: true,
|
|
33
|
+
generateMiddlewareResponse: async (query) => {
|
|
34
|
+
try {
|
|
35
|
+
return handleQueryResult(await query(request));
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return handleQueryError(error);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
normalizePath: (r) => getNormalizedPath(r)
|
|
41
|
+
}));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return handleQueryError(error);
|
|
44
|
+
}
|
|
45
|
+
function handleQueryResult(result) {
|
|
46
|
+
return isResponse(result) ? result : staticContextToResponse(result);
|
|
47
|
+
}
|
|
48
|
+
function handleQueryError(error, status = 500) {
|
|
49
|
+
handleError(error);
|
|
50
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
51
|
+
result: { error },
|
|
52
|
+
headers: new Headers(),
|
|
53
|
+
status
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function staticContextToResponse(context) {
|
|
57
|
+
let headers = getDocumentHeaders(context, build);
|
|
58
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) return new Response(null, {
|
|
59
|
+
status: context.statusCode,
|
|
60
|
+
headers
|
|
61
|
+
});
|
|
62
|
+
if (context.errors) {
|
|
63
|
+
Object.values(context.errors).forEach((err) => {
|
|
64
|
+
if (!isRouteErrorResponse(err) || err.error) handleError(err);
|
|
65
|
+
});
|
|
66
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
67
|
+
}
|
|
68
|
+
let singleFetchResult;
|
|
69
|
+
if (context.errors) singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
70
|
+
else singleFetchResult = { data: Object.values(context.actionData || {})[0] };
|
|
71
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
72
|
+
result: singleFetchResult,
|
|
73
|
+
headers,
|
|
74
|
+
status: context.statusCode
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function singleFetchLoaders(build, serverMode, staticHandler, request, loadContext, handleError) {
|
|
79
|
+
let routesParam = new URL(request.url).searchParams.get("_routes");
|
|
80
|
+
let loadRouteIds = routesParam ? new Set(routesParam.split(",")) : null;
|
|
81
|
+
try {
|
|
82
|
+
return handleQueryResult(await staticHandler.query(request, {
|
|
83
|
+
requestContext: loadContext,
|
|
84
|
+
filterMatchesToLoad: (m) => !loadRouteIds || loadRouteIds.has(m.route.id),
|
|
85
|
+
skipLoaderErrorBubbling: true,
|
|
86
|
+
generateMiddlewareResponse: async (query) => {
|
|
87
|
+
try {
|
|
88
|
+
return handleQueryResult(await query(request));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return handleQueryError(error);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
normalizePath: (r) => getNormalizedPath(r)
|
|
94
|
+
}));
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return handleQueryError(error);
|
|
97
|
+
}
|
|
98
|
+
function handleQueryResult(result) {
|
|
99
|
+
return isResponse(result) ? result : staticContextToResponse(result);
|
|
100
|
+
}
|
|
101
|
+
function handleQueryError(error) {
|
|
102
|
+
handleError(error);
|
|
103
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
104
|
+
result: { error },
|
|
105
|
+
headers: new Headers(),
|
|
106
|
+
status: 500
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function staticContextToResponse(context) {
|
|
110
|
+
let headers = getDocumentHeaders(context, build);
|
|
111
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) return new Response(null, {
|
|
112
|
+
status: context.statusCode,
|
|
113
|
+
headers
|
|
114
|
+
});
|
|
115
|
+
if (context.errors) {
|
|
116
|
+
Object.values(context.errors).forEach((err) => {
|
|
117
|
+
if (!isRouteErrorResponse(err) || err.error) handleError(err);
|
|
118
|
+
});
|
|
119
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
120
|
+
}
|
|
121
|
+
let results = {};
|
|
122
|
+
let loadedMatches = new Set(context.matches.filter((m) => loadRouteIds ? loadRouteIds.has(m.route.id) : m.route.loader != null).map((m) => m.route.id));
|
|
123
|
+
if (context.errors) for (let [id, error] of Object.entries(context.errors)) results[id] = { error };
|
|
124
|
+
for (let [id, data] of Object.entries(context.loaderData)) if (!(id in results) && loadedMatches.has(id)) results[id] = { data };
|
|
125
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
126
|
+
result: results,
|
|
127
|
+
headers,
|
|
128
|
+
status: context.statusCode
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function generateSingleFetchResponse(request, build, serverMode, { result, headers, status }) {
|
|
133
|
+
let resultHeaders = new Headers(headers);
|
|
134
|
+
resultHeaders.set("X-Remix-Response", "yes");
|
|
135
|
+
if (SERVER_NO_BODY_STATUS_CODES.has(status)) return new Response(null, {
|
|
136
|
+
status,
|
|
137
|
+
headers: resultHeaders
|
|
138
|
+
});
|
|
139
|
+
resultHeaders.set("Content-Type", "text/x-script");
|
|
140
|
+
resultHeaders.delete("Content-Length");
|
|
141
|
+
return new Response(encodeViaTurboStream(result, request.signal, build.entry.module.streamTimeout, serverMode), {
|
|
142
|
+
status: status || 200,
|
|
143
|
+
headers: resultHeaders
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function generateSingleFetchRedirectResponse(redirectResponse, request, build, serverMode) {
|
|
147
|
+
let redirect = getSingleFetchRedirect(redirectResponse.status, redirectResponse.headers, build.basename);
|
|
148
|
+
let headers = new Headers(redirectResponse.headers);
|
|
149
|
+
headers.delete("Location");
|
|
150
|
+
headers.set("Content-Type", "text/x-script");
|
|
151
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
152
|
+
result: request.method === "GET" ? { [SingleFetchRedirectSymbol]: redirect } : redirect,
|
|
153
|
+
headers,
|
|
154
|
+
status: 202
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function getSingleFetchRedirect(status, headers, basename) {
|
|
158
|
+
let redirect = headers.get("Location");
|
|
159
|
+
if (basename) redirect = stripBasename(redirect, basename) || redirect;
|
|
160
|
+
return {
|
|
161
|
+
redirect,
|
|
162
|
+
status,
|
|
163
|
+
revalidate: headers.has("X-Remix-Revalidate") || headers.has("Set-Cookie"),
|
|
164
|
+
reload: headers.has("X-Remix-Reload-Document"),
|
|
165
|
+
replace: headers.has("X-Remix-Replace")
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function encodeViaTurboStream(data, requestSignal, streamTimeout, serverMode) {
|
|
169
|
+
let controller = new AbortController();
|
|
170
|
+
let timeoutId = setTimeout(() => {
|
|
171
|
+
controller.abort(/* @__PURE__ */ new Error("Server Timeout"));
|
|
172
|
+
cleanupCallbacks();
|
|
173
|
+
}, typeof streamTimeout === "number" ? streamTimeout : 4950);
|
|
174
|
+
let abortControllerOnRequestAbort = () => {
|
|
175
|
+
controller.abort(requestSignal.reason);
|
|
176
|
+
cleanupCallbacks();
|
|
177
|
+
};
|
|
178
|
+
requestSignal.addEventListener("abort", abortControllerOnRequestAbort);
|
|
179
|
+
let cleanupCallbacks = () => {
|
|
180
|
+
clearTimeout(timeoutId);
|
|
181
|
+
requestSignal.removeEventListener("abort", abortControllerOnRequestAbort);
|
|
182
|
+
};
|
|
183
|
+
return encode(data, {
|
|
184
|
+
signal: controller.signal,
|
|
185
|
+
onComplete: cleanupCallbacks,
|
|
186
|
+
plugins: [(value) => {
|
|
187
|
+
if (value instanceof Error) {
|
|
188
|
+
let { name, message, stack } = serverMode === "production" ? sanitizeError(value, serverMode) : value;
|
|
189
|
+
return [
|
|
190
|
+
"SanitizedError",
|
|
191
|
+
name,
|
|
192
|
+
message,
|
|
193
|
+
stack
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
if (value instanceof ErrorResponseImpl) {
|
|
197
|
+
let { data, status, statusText } = value;
|
|
198
|
+
return [
|
|
199
|
+
"ErrorResponse",
|
|
200
|
+
data,
|
|
201
|
+
status,
|
|
202
|
+
statusText
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
if (value && typeof value === "object" && SingleFetchRedirectSymbol in value) return ["SingleFetchRedirect", value[SingleFetchRedirectSymbol]];
|
|
206
|
+
}],
|
|
207
|
+
postPlugins: [(value) => {
|
|
208
|
+
if (!value) return;
|
|
209
|
+
if (typeof value !== "object") return;
|
|
210
|
+
return ["SingleFetchClassInstance", Object.fromEntries(Object.entries(value))];
|
|
211
|
+
}, () => ["SingleFetchFallback"]]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { SERVER_NO_BODY_STATUS_CODES, encodeViaTurboStream, generateSingleFetchRedirectResponse, singleFetchAction, singleFetchLoaders };
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
//#region lib/server-runtime/urls.ts
|
|
12
|
+
function getNormalizedPath(request) {
|
|
13
|
+
let url = new URL(request.url);
|
|
14
|
+
let pathname = url.pathname;
|
|
15
|
+
if (pathname.endsWith("/_.data")) pathname = pathname.replace(/_\.data$/, "");
|
|
16
|
+
else pathname = pathname.replace(/\.data$/, "");
|
|
17
|
+
let searchParams = new URLSearchParams(url.search);
|
|
18
|
+
searchParams.delete("_routes");
|
|
19
|
+
let search = searchParams.toString();
|
|
20
|
+
if (search) search = `?${search}`;
|
|
21
|
+
return {
|
|
22
|
+
pathname,
|
|
23
|
+
search,
|
|
24
|
+
hash: ""
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getNormalizedPath };
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
//#region lib/server-runtime/warnings.ts
|
|
12
|
+
const alreadyWarned = {};
|
|
13
|
+
function warnOnce(condition, message) {
|
|
14
|
+
if (!condition && !alreadyWarned[message]) {
|
|
15
|
+
alreadyWarned[message] = true;
|
|
16
|
+
console.warn(message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { warnOnce };
|