react-router 7.16.0 → 8.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1007
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1645 -1635
- package/dist/development/index-react-server.js +2880 -3642
- package/dist/development/index.d.ts +43 -1475
- package/dist/development/index.js +37 -2621
- package/dist/development/lib/actions.js +62 -0
- package/dist/development/lib/components.d.ts +1022 -0
- package/dist/development/lib/components.js +835 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2042 -0
- package/dist/development/lib/dom/lib.js +1259 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +196 -0
- package/dist/development/lib/dom/ssr/components.js +579 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/development/lib/dom/ssr/errors.js +36 -0
- package/dist/development/lib/dom/ssr/fallback.js +28 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +45 -0
- package/dist/development/lib/dom/ssr/server.js +68 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +153 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1386 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +371 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +113 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2981 -0
- package/dist/development/lib/router/utils.d.ts +942 -0
- package/dist/development/lib/router/utils.js +791 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +599 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +388 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +95 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +351 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +31 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/{production/register-CNAx3TXj.d.ts → development/lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1007
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1645 -1635
- package/dist/production/index-react-server.js +2871 -3642
- package/dist/production/index.d.ts +43 -1475
- package/dist/production/index.js +37 -2621
- package/dist/production/lib/actions.js +62 -0
- package/dist/production/lib/components.d.ts +1022 -0
- package/dist/production/lib/components.js +835 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2042 -0
- package/dist/production/lib/dom/lib.js +1259 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +196 -0
- package/dist/production/lib/dom/ssr/components.js +579 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/production/lib/dom/ssr/errors.js +36 -0
- package/dist/production/lib/dom/ssr/fallback.js +21 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +45 -0
- package/dist/production/lib/dom/ssr/server.js +68 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +153 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1371 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +371 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +113 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2981 -0
- package/dist/production/lib/router/utils.d.ts +942 -0
- package/dist/production/lib/router/utils.js +782 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +599 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +388 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +95 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +351 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +31 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/{development/register-CNAx3TXj.d.ts → production/lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
- package/docs/explanation/backend-for-frontend.md +50 -0
- package/docs/explanation/code-splitting.md +77 -0
- package/docs/explanation/concurrency.md +135 -0
- package/docs/explanation/form-vs-fetcher.md +292 -0
- package/docs/explanation/hot-module-replacement.md +137 -0
- package/docs/explanation/hydration.md +14 -0
- package/docs/explanation/index-query-param.md +86 -0
- package/docs/explanation/index.md +4 -0
- package/docs/explanation/lazy-route-discovery.md +78 -0
- package/docs/explanation/location.md +6 -0
- package/docs/explanation/progressive-enhancement.md +150 -0
- package/docs/explanation/race-conditions.md +88 -0
- package/docs/explanation/react-transitions.md +160 -0
- package/docs/explanation/route-matching.md +7 -0
- package/docs/explanation/server-client-execution.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +465 -0
- package/docs/explanation/special-files.md +16 -0
- package/docs/explanation/state-management.md +524 -0
- package/docs/explanation/styling.md +87 -0
- package/docs/explanation/type-safety.md +82 -0
- package/docs/how-to/accessibility.md +44 -0
- package/docs/how-to/client-data.md +199 -0
- package/docs/how-to/data-strategy.md +317 -0
- package/docs/how-to/error-boundary.md +231 -0
- package/docs/how-to/error-reporting.md +134 -0
- package/docs/how-to/fetchers.md +307 -0
- package/docs/how-to/file-route-conventions.md +410 -0
- package/docs/how-to/file-uploads.md +217 -0
- package/docs/how-to/form-validation.md +120 -0
- package/docs/how-to/headers.md +164 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +556 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +728 -0
- package/docs/how-to/navigation-blocking.md +233 -0
- package/docs/how-to/optimize-revalidation.md +12 -0
- package/docs/how-to/pre-rendering.md +225 -0
- package/docs/how-to/presets.md +103 -0
- package/docs/how-to/react-server-components.md +899 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +100 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +30 -0
- package/docs/how-to/server-bundles.md +66 -0
- package/docs/how-to/spa.md +120 -0
- package/docs/how-to/status.md +63 -0
- package/docs/how-to/suspense.md +132 -0
- package/docs/how-to/using-handle.md +117 -0
- package/docs/how-to/view-transitions.md +237 -0
- package/docs/how-to/webhook.md +50 -0
- package/docs/index.md +39 -0
- package/docs/start/data/actions.md +138 -0
- package/docs/start/data/custom.md +198 -0
- package/docs/start/data/data-loading.md +44 -0
- package/docs/start/data/index.md +4 -0
- package/docs/start/data/installation.md +52 -0
- package/docs/start/data/navigating.md +12 -0
- package/docs/start/data/pending-ui.md +12 -0
- package/docs/start/data/route-object.md +248 -0
- package/docs/start/data/routing.md +281 -0
- package/docs/start/data/testing.md +8 -0
- package/docs/start/declarative/index.md +4 -0
- package/docs/start/declarative/installation.md +43 -0
- package/docs/start/declarative/navigating.md +133 -0
- package/docs/start/declarative/routing.md +237 -0
- package/docs/start/declarative/url-values.md +65 -0
- package/docs/start/framework/actions.md +175 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +96 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +42 -0
- package/docs/start/framework/navigating.md +182 -0
- package/docs/start/framework/pending-ui.md +142 -0
- package/docs/start/framework/rendering.md +59 -0
- package/docs/start/framework/route-module.md +527 -0
- package/docs/start/framework/routing.md +362 -0
- package/docs/start/framework/testing.md +133 -0
- package/docs/start/index.md +4 -0
- package/docs/start/modes.md +201 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +31 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/remix.md +403 -0
- package/docs/upgrading/router-provider.md +442 -0
- package/docs/upgrading/v6.md +379 -0
- package/package.json +44 -87
- package/dist/development/browser-D3uq9sI1.d.ts +0 -318
- package/dist/development/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/development/chunk-IBI7OMNB.js +0 -1363
- package/dist/development/chunk-QUQL4437.mjs +0 -11529
- package/dist/development/chunk-S54KXAEJ.mjs +0 -2585
- package/dist/development/chunk-SRID2YZ2.js +0 -10229
- package/dist/development/chunk-XEJDWL2B.js +0 -188
- package/dist/development/context-m8rizgnE.d.mts +0 -1771
- package/dist/development/data-D4xhSy90.d.ts +0 -1732
- package/dist/development/data-U8FS-wNn.d.mts +0 -1732
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1008
- package/dist/development/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/development/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2703
- package/dist/development/index-react-server.mjs +0 -3780
- package/dist/development/index.d.mts +0 -1478
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-CqK96Zfk.d.mts +0 -30
- package/dist/production/browser-D3uq9sI1.d.ts +0 -318
- package/dist/production/browser-nIQ4Nsyi.d.mts +0 -318
- package/dist/production/chunk-EAQNHM3N.js +0 -188
- package/dist/production/chunk-NALGHHKE.mjs +0 -2585
- package/dist/production/chunk-Q65P7S7Y.mjs +0 -11529
- package/dist/production/chunk-SKEDDLRM.js +0 -1363
- package/dist/production/chunk-Y7DNFQZP.js +0 -10229
- package/dist/production/context-m8rizgnE.d.mts +0 -1771
- package/dist/production/data-D4xhSy90.d.ts +0 -1732
- package/dist/production/data-U8FS-wNn.d.mts +0 -1732
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1008
- package/dist/production/index-react-server-client-BLiUx67a.d.ts +0 -3655
- package/dist/production/index-react-server-client-CdKROblb.d.mts +0 -2600
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2703
- package/dist/production/index-react-server.mjs +0 -3780
- package/dist/production/index.d.mts +0 -1478
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-1q4YhLGP.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-CqK96Zfk.d.mts +0 -30
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { matchRoutes } from "../../router/utils.js";
|
|
12
|
+
import { DataRouterContext, DataRouterStateContext, useIsRSCRouterContext } from "../../context.js";
|
|
13
|
+
import { useLocation } from "../../hooks.js";
|
|
14
|
+
import { warnOnce } from "../../server-runtime/warnings.js";
|
|
15
|
+
import invariant from "./invariant.js";
|
|
16
|
+
import { getKeyedLinksForMatches, getKeyedPrefetchLinks, getModuleLinkHrefs, getNewMatchesForLinks, isPageLinkDescriptor } from "./links.js";
|
|
17
|
+
import { escapeHtml } from "./markup.js";
|
|
18
|
+
import { singleFetchUrl } from "./single-fetch.js";
|
|
19
|
+
import { getPartialManifest, isFogOfWarEnabled } from "./fog-of-war.js";
|
|
20
|
+
import * as React$1 from "react";
|
|
21
|
+
//#region lib/dom/ssr/components.tsx
|
|
22
|
+
function useDataRouterContext() {
|
|
23
|
+
let context = React$1.useContext(DataRouterContext);
|
|
24
|
+
invariant(context, "You must render this element inside a <DataRouterContext.Provider> element");
|
|
25
|
+
return context;
|
|
26
|
+
}
|
|
27
|
+
function useDataRouterStateContext() {
|
|
28
|
+
let context = React$1.useContext(DataRouterStateContext);
|
|
29
|
+
invariant(context, "You must render this element inside a <DataRouterStateContext.Provider> element");
|
|
30
|
+
return context;
|
|
31
|
+
}
|
|
32
|
+
const FrameworkContext = React$1.createContext(void 0);
|
|
33
|
+
FrameworkContext.displayName = "FrameworkContext";
|
|
34
|
+
function useFrameworkContext() {
|
|
35
|
+
let context = React$1.useContext(FrameworkContext);
|
|
36
|
+
invariant(context, "You must render this element inside a <HydratedRouter> element");
|
|
37
|
+
return context;
|
|
38
|
+
}
|
|
39
|
+
function usePrefetchBehavior(prefetch, theirElementProps) {
|
|
40
|
+
let frameworkContext = React$1.useContext(FrameworkContext);
|
|
41
|
+
let [maybePrefetch, setMaybePrefetch] = React$1.useState(false);
|
|
42
|
+
let [shouldPrefetch, setShouldPrefetch] = React$1.useState(false);
|
|
43
|
+
let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
44
|
+
let ref = React$1.useRef(null);
|
|
45
|
+
React$1.useEffect(() => {
|
|
46
|
+
if (prefetch === "render") setShouldPrefetch(true);
|
|
47
|
+
if (prefetch === "viewport") {
|
|
48
|
+
let callback = (entries) => {
|
|
49
|
+
entries.forEach((entry) => {
|
|
50
|
+
setShouldPrefetch(entry.isIntersecting);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
let observer = new IntersectionObserver(callback, { threshold: .5 });
|
|
54
|
+
if (ref.current) observer.observe(ref.current);
|
|
55
|
+
return () => {
|
|
56
|
+
observer.disconnect();
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}, [prefetch]);
|
|
60
|
+
React$1.useEffect(() => {
|
|
61
|
+
if (maybePrefetch) {
|
|
62
|
+
let id = setTimeout(() => {
|
|
63
|
+
setShouldPrefetch(true);
|
|
64
|
+
}, 100);
|
|
65
|
+
return () => {
|
|
66
|
+
clearTimeout(id);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}, [maybePrefetch]);
|
|
70
|
+
let setIntent = () => {
|
|
71
|
+
setMaybePrefetch(true);
|
|
72
|
+
};
|
|
73
|
+
let cancelIntent = () => {
|
|
74
|
+
setMaybePrefetch(false);
|
|
75
|
+
setShouldPrefetch(false);
|
|
76
|
+
};
|
|
77
|
+
if (!frameworkContext) return [
|
|
78
|
+
false,
|
|
79
|
+
ref,
|
|
80
|
+
{}
|
|
81
|
+
];
|
|
82
|
+
if (prefetch !== "intent") return [
|
|
83
|
+
shouldPrefetch,
|
|
84
|
+
ref,
|
|
85
|
+
{}
|
|
86
|
+
];
|
|
87
|
+
return [
|
|
88
|
+
shouldPrefetch,
|
|
89
|
+
ref,
|
|
90
|
+
{
|
|
91
|
+
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
92
|
+
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
93
|
+
onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
|
94
|
+
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
95
|
+
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
function composeEventHandlers(theirHandler, ourHandler) {
|
|
100
|
+
return (event) => {
|
|
101
|
+
theirHandler && theirHandler(event);
|
|
102
|
+
if (!event.defaultPrevented) ourHandler(event);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function getActiveMatches(matches, errors, isSpaMode) {
|
|
106
|
+
if (isSpaMode && !isHydrated) return [matches[0]];
|
|
107
|
+
if (errors) {
|
|
108
|
+
let errorIdx = matches.findIndex((m) => errors[m.route.id] !== void 0);
|
|
109
|
+
return matches.slice(0, errorIdx + 1);
|
|
110
|
+
}
|
|
111
|
+
return matches;
|
|
112
|
+
}
|
|
113
|
+
const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
|
|
114
|
+
/**
|
|
115
|
+
* Renders all the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
116
|
+
* tags created by the route module's [`links`](../../start/framework/route-module#links)
|
|
117
|
+
* export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
|
|
118
|
+
* of your document.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* import { Links } from "react-router";
|
|
122
|
+
*
|
|
123
|
+
* export default function Root() {
|
|
124
|
+
* return (
|
|
125
|
+
* <html>
|
|
126
|
+
* <head>
|
|
127
|
+
* <Links />
|
|
128
|
+
* </head>
|
|
129
|
+
* <body></body>
|
|
130
|
+
* </html>
|
|
131
|
+
* );
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @category Components
|
|
136
|
+
* @mode framework
|
|
137
|
+
* @param props Props
|
|
138
|
+
* @param {LinksProps.nonce} props.nonce n/a
|
|
139
|
+
* @param {LinksProps.crossOrigin} props.crossOrigin n/a
|
|
140
|
+
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
141
|
+
* tags
|
|
142
|
+
*/
|
|
143
|
+
function Links({ nonce, crossOrigin }) {
|
|
144
|
+
let { isSpaMode, manifest, routeModules, criticalCss } = useFrameworkContext();
|
|
145
|
+
let { errors, matches: routerMatches } = useDataRouterStateContext();
|
|
146
|
+
let matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
|
147
|
+
let keyedLinks = React$1.useMemo(() => getKeyedLinksForMatches(matches, routeModules, manifest), [
|
|
148
|
+
matches,
|
|
149
|
+
routeModules,
|
|
150
|
+
manifest
|
|
151
|
+
]);
|
|
152
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof criticalCss === "string" ? /* @__PURE__ */ React$1.createElement("style", {
|
|
153
|
+
[CRITICAL_CSS_DATA_ATTRIBUTE]: "",
|
|
154
|
+
nonce,
|
|
155
|
+
dangerouslySetInnerHTML: { __html: criticalCss }
|
|
156
|
+
}) : null, typeof criticalCss === "object" ? /* @__PURE__ */ React$1.createElement("link", {
|
|
157
|
+
[CRITICAL_CSS_DATA_ATTRIBUTE]: "",
|
|
158
|
+
rel: "stylesheet",
|
|
159
|
+
href: criticalCss.href,
|
|
160
|
+
nonce,
|
|
161
|
+
crossOrigin
|
|
162
|
+
}) : null, keyedLinks.map(({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, {
|
|
163
|
+
key,
|
|
164
|
+
nonce,
|
|
165
|
+
...link,
|
|
166
|
+
crossOrigin: link.crossOrigin ?? crossOrigin
|
|
167
|
+
}) : /* @__PURE__ */ React$1.createElement("link", {
|
|
168
|
+
key,
|
|
169
|
+
nonce,
|
|
170
|
+
...link,
|
|
171
|
+
crossOrigin: link.crossOrigin ?? crossOrigin
|
|
172
|
+
})));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Renders [`<link rel=prefetch|modulepreload>`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel)
|
|
176
|
+
* tags for modules and data of another page to enable an instant navigation to
|
|
177
|
+
* that page. [`<Link prefetch>`](./Link#prefetch) uses this internally, but you
|
|
178
|
+
* can render it to prefetch a page for any other reason.
|
|
179
|
+
*
|
|
180
|
+
* For example, you may render one of this as the user types into a search field
|
|
181
|
+
* to prefetch search results before they click through to their selection.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* import { PrefetchPageLinks } from "react-router";
|
|
185
|
+
*
|
|
186
|
+
* <PrefetchPageLinks page="/absolute/path" />
|
|
187
|
+
*
|
|
188
|
+
* @public
|
|
189
|
+
* @category Components
|
|
190
|
+
* @mode framework
|
|
191
|
+
* @param props Props
|
|
192
|
+
* @param {PageLinkDescriptor.page} props.page n/a
|
|
193
|
+
* @param props.linkProps Additional props to spread onto the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
194
|
+
* tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin),
|
|
195
|
+
* [`integrity`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/integrity),
|
|
196
|
+
* [`rel`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel),
|
|
197
|
+
* etc.
|
|
198
|
+
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
199
|
+
* tags
|
|
200
|
+
*/
|
|
201
|
+
function PrefetchPageLinks({ page, ...linkProps }) {
|
|
202
|
+
let rsc = useIsRSCRouterContext();
|
|
203
|
+
let { router } = useDataRouterContext();
|
|
204
|
+
let matches = React$1.useMemo(() => matchRoutes(router.routes, page, router.basename), [
|
|
205
|
+
router.routes,
|
|
206
|
+
page,
|
|
207
|
+
router.basename
|
|
208
|
+
]);
|
|
209
|
+
if (!matches) return null;
|
|
210
|
+
if (rsc) return /* @__PURE__ */ React$1.createElement(RSCPrefetchPageLinksImpl, {
|
|
211
|
+
page,
|
|
212
|
+
matches,
|
|
213
|
+
...linkProps
|
|
214
|
+
});
|
|
215
|
+
return /* @__PURE__ */ React$1.createElement(PrefetchPageLinksImpl, {
|
|
216
|
+
page,
|
|
217
|
+
matches,
|
|
218
|
+
...linkProps
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function useKeyedPrefetchLinks(matches) {
|
|
222
|
+
let { manifest, routeModules } = useFrameworkContext();
|
|
223
|
+
let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React$1.useState([]);
|
|
224
|
+
React$1.useEffect(() => {
|
|
225
|
+
let interrupted = false;
|
|
226
|
+
getKeyedPrefetchLinks(matches, manifest, routeModules).then((links) => {
|
|
227
|
+
if (!interrupted) setKeyedPrefetchLinks(links);
|
|
228
|
+
});
|
|
229
|
+
return () => {
|
|
230
|
+
interrupted = true;
|
|
231
|
+
};
|
|
232
|
+
}, [
|
|
233
|
+
matches,
|
|
234
|
+
manifest,
|
|
235
|
+
routeModules
|
|
236
|
+
]);
|
|
237
|
+
return keyedPrefetchLinks;
|
|
238
|
+
}
|
|
239
|
+
function RSCPrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
|
|
240
|
+
let location = useLocation();
|
|
241
|
+
let dataHrefs = React$1.useMemo(() => {
|
|
242
|
+
if (page === location.pathname + location.search + location.hash) return [];
|
|
243
|
+
let url = singleFetchUrl(page, "rsc");
|
|
244
|
+
let hasSomeRoutesWithShouldRevalidate = false;
|
|
245
|
+
let targetRoutes = [];
|
|
246
|
+
for (let match of nextMatches) if (typeof match.route.shouldRevalidate === "function") hasSomeRoutesWithShouldRevalidate = true;
|
|
247
|
+
else targetRoutes.push(match.route.id);
|
|
248
|
+
if (hasSomeRoutesWithShouldRevalidate && targetRoutes.length > 0) url.searchParams.set("_routes", targetRoutes.join(","));
|
|
249
|
+
return [url.pathname + url.search];
|
|
250
|
+
}, [
|
|
251
|
+
page,
|
|
252
|
+
location,
|
|
253
|
+
nextMatches
|
|
254
|
+
]);
|
|
255
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
|
|
256
|
+
key: href,
|
|
257
|
+
rel: "prefetch",
|
|
258
|
+
as: "fetch",
|
|
259
|
+
href,
|
|
260
|
+
...linkProps
|
|
261
|
+
})));
|
|
262
|
+
}
|
|
263
|
+
function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
|
|
264
|
+
let location = useLocation();
|
|
265
|
+
let { manifest, routeModules } = useFrameworkContext();
|
|
266
|
+
let { loaderData, matches } = useDataRouterStateContext();
|
|
267
|
+
let newMatchesForData = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "data"), [
|
|
268
|
+
page,
|
|
269
|
+
nextMatches,
|
|
270
|
+
matches,
|
|
271
|
+
manifest,
|
|
272
|
+
location
|
|
273
|
+
]);
|
|
274
|
+
let newMatchesForAssets = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "assets"), [
|
|
275
|
+
page,
|
|
276
|
+
nextMatches,
|
|
277
|
+
matches,
|
|
278
|
+
manifest,
|
|
279
|
+
location
|
|
280
|
+
]);
|
|
281
|
+
let dataHrefs = React$1.useMemo(() => {
|
|
282
|
+
if (page === location.pathname + location.search + location.hash) return [];
|
|
283
|
+
let routesParams = /* @__PURE__ */ new Set();
|
|
284
|
+
let foundOptOutRoute = false;
|
|
285
|
+
nextMatches.forEach((m) => {
|
|
286
|
+
let manifestRoute = manifest.routes[m.route.id];
|
|
287
|
+
if (!manifestRoute || !manifestRoute.hasLoader) return;
|
|
288
|
+
if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) foundOptOutRoute = true;
|
|
289
|
+
else if (manifestRoute.hasClientLoader) foundOptOutRoute = true;
|
|
290
|
+
else routesParams.add(m.route.id);
|
|
291
|
+
});
|
|
292
|
+
if (routesParams.size === 0) return [];
|
|
293
|
+
let url = singleFetchUrl(page, "data");
|
|
294
|
+
if (foundOptOutRoute && routesParams.size > 0) url.searchParams.set("_routes", nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(","));
|
|
295
|
+
return [url.pathname + url.search];
|
|
296
|
+
}, [
|
|
297
|
+
loaderData,
|
|
298
|
+
location,
|
|
299
|
+
manifest,
|
|
300
|
+
newMatchesForData,
|
|
301
|
+
nextMatches,
|
|
302
|
+
page,
|
|
303
|
+
routeModules
|
|
304
|
+
]);
|
|
305
|
+
let moduleHrefs = React$1.useMemo(() => getModuleLinkHrefs(newMatchesForAssets, manifest), [newMatchesForAssets, manifest]);
|
|
306
|
+
let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
|
|
307
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
|
|
308
|
+
key: href,
|
|
309
|
+
rel: "prefetch",
|
|
310
|
+
as: "fetch",
|
|
311
|
+
href,
|
|
312
|
+
...linkProps
|
|
313
|
+
})), moduleHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
|
|
314
|
+
key: href,
|
|
315
|
+
rel: "modulepreload",
|
|
316
|
+
href,
|
|
317
|
+
...linkProps
|
|
318
|
+
})), keyedPrefetchLinks.map(({ key, link }) => /* @__PURE__ */ React$1.createElement("link", {
|
|
319
|
+
key,
|
|
320
|
+
nonce: linkProps.nonce,
|
|
321
|
+
...link,
|
|
322
|
+
crossOrigin: link.crossOrigin ?? linkProps.crossOrigin
|
|
323
|
+
})));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Renders all the [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
|
|
327
|
+
* tags created by the route module's [`meta`](../../start/framework/route-module#meta)
|
|
328
|
+
* export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
|
|
329
|
+
* of your document.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* import { Meta } from "react-router";
|
|
333
|
+
*
|
|
334
|
+
* export default function Root() {
|
|
335
|
+
* return (
|
|
336
|
+
* <html>
|
|
337
|
+
* <head>
|
|
338
|
+
* <Meta />
|
|
339
|
+
* </head>
|
|
340
|
+
* </html>
|
|
341
|
+
* );
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* @public
|
|
345
|
+
* @category Components
|
|
346
|
+
* @mode framework
|
|
347
|
+
* @returns A collection of React elements for [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
|
|
348
|
+
* tags
|
|
349
|
+
*/
|
|
350
|
+
function Meta() {
|
|
351
|
+
let { isSpaMode, routeModules } = useFrameworkContext();
|
|
352
|
+
let { errors, matches: routerMatches, loaderData } = useDataRouterStateContext();
|
|
353
|
+
let location = useLocation();
|
|
354
|
+
let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
|
355
|
+
let error = null;
|
|
356
|
+
if (errors) error = errors[_matches[_matches.length - 1].route.id];
|
|
357
|
+
let meta = [];
|
|
358
|
+
let leafMeta = null;
|
|
359
|
+
let matches = [];
|
|
360
|
+
for (let i = 0; i < _matches.length; i++) {
|
|
361
|
+
let _match = _matches[i];
|
|
362
|
+
let routeId = _match.route.id;
|
|
363
|
+
let data = loaderData[routeId];
|
|
364
|
+
let params = _match.params;
|
|
365
|
+
let routeModule = routeModules[routeId];
|
|
366
|
+
let routeMeta = [];
|
|
367
|
+
let match = {
|
|
368
|
+
id: routeId,
|
|
369
|
+
loaderData: data,
|
|
370
|
+
meta: [],
|
|
371
|
+
params: _match.params,
|
|
372
|
+
pathname: _match.pathname,
|
|
373
|
+
handle: _match.route.handle,
|
|
374
|
+
error
|
|
375
|
+
};
|
|
376
|
+
matches[i] = match;
|
|
377
|
+
if (routeModule?.meta) routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
|
|
378
|
+
loaderData: data,
|
|
379
|
+
params,
|
|
380
|
+
location,
|
|
381
|
+
matches,
|
|
382
|
+
error
|
|
383
|
+
}) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
|
|
384
|
+
else if (leafMeta) routeMeta = [...leafMeta];
|
|
385
|
+
routeMeta = routeMeta || [];
|
|
386
|
+
if (!Array.isArray(routeMeta)) throw new Error("The route at " + _match.route.path + " returns an invalid value. All route meta functions must return an array of meta objects.\n\nTo reference the meta function API, see https://reactrouter.com/start/framework/route-module#meta");
|
|
387
|
+
match.meta = routeMeta;
|
|
388
|
+
matches[i] = match;
|
|
389
|
+
meta = [...routeMeta];
|
|
390
|
+
leafMeta = meta;
|
|
391
|
+
}
|
|
392
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, meta.flat().map((metaProps) => {
|
|
393
|
+
if (!metaProps) return null;
|
|
394
|
+
if ("tagName" in metaProps) {
|
|
395
|
+
let { tagName, ...rest } = metaProps;
|
|
396
|
+
if (!isValidMetaTag(tagName)) {
|
|
397
|
+
console.warn(`A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'`);
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
let Comp = tagName;
|
|
401
|
+
return /* @__PURE__ */ React$1.createElement(Comp, {
|
|
402
|
+
key: JSON.stringify(rest),
|
|
403
|
+
...rest
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if ("title" in metaProps) return /* @__PURE__ */ React$1.createElement("title", { key: "title" }, String(metaProps.title));
|
|
407
|
+
if ("charset" in metaProps) {
|
|
408
|
+
metaProps.charSet ??= metaProps.charset;
|
|
409
|
+
delete metaProps.charset;
|
|
410
|
+
}
|
|
411
|
+
if ("charSet" in metaProps && metaProps.charSet != null) return typeof metaProps.charSet === "string" ? /* @__PURE__ */ React$1.createElement("meta", {
|
|
412
|
+
key: "charSet",
|
|
413
|
+
charSet: metaProps.charSet
|
|
414
|
+
}) : null;
|
|
415
|
+
if ("script:ld+json" in metaProps) try {
|
|
416
|
+
let json = JSON.stringify(metaProps["script:ld+json"]);
|
|
417
|
+
return /* @__PURE__ */ React$1.createElement("script", {
|
|
418
|
+
key: `script:ld+json:${json}`,
|
|
419
|
+
type: "application/ld+json",
|
|
420
|
+
dangerouslySetInnerHTML: { __html: escapeHtml(json) }
|
|
421
|
+
});
|
|
422
|
+
} catch (e) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
return /* @__PURE__ */ React$1.createElement("meta", {
|
|
426
|
+
key: JSON.stringify(metaProps),
|
|
427
|
+
...metaProps
|
|
428
|
+
});
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
function isValidMetaTag(tagName) {
|
|
432
|
+
return typeof tagName === "string" && /^(meta|link)$/.test(tagName);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Tracks whether hydration is finished, so scripts can be skipped
|
|
436
|
+
* during client-side updates.
|
|
437
|
+
*/
|
|
438
|
+
let isHydrated = false;
|
|
439
|
+
function setIsHydrated() {
|
|
440
|
+
isHydrated = true;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Renders the client runtime of your app. It should be rendered inside the
|
|
444
|
+
* [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
|
|
445
|
+
* of the document.
|
|
446
|
+
*
|
|
447
|
+
* If server rendering, you can omit `<Scripts/>` and the app will work as a
|
|
448
|
+
* traditional web app without JavaScript, relying solely on HTML and browser
|
|
449
|
+
* behaviors.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* import { Scripts } from "react-router";
|
|
453
|
+
*
|
|
454
|
+
* export default function Root() {
|
|
455
|
+
* return (
|
|
456
|
+
* <html>
|
|
457
|
+
* <head />
|
|
458
|
+
* <body>
|
|
459
|
+
* <Scripts />
|
|
460
|
+
* </body>
|
|
461
|
+
* </html>
|
|
462
|
+
* );
|
|
463
|
+
* }
|
|
464
|
+
*
|
|
465
|
+
* @public
|
|
466
|
+
* @category Components
|
|
467
|
+
* @mode framework
|
|
468
|
+
* @param scriptProps Additional props to spread onto the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
|
|
469
|
+
* tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin),
|
|
470
|
+
* [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce),
|
|
471
|
+
* etc.
|
|
472
|
+
* @returns A collection of React elements for [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
|
|
473
|
+
* tags
|
|
474
|
+
*/
|
|
475
|
+
function Scripts(scriptProps) {
|
|
476
|
+
let { manifest, serverHandoffString, isSpaMode, renderMeta, routeDiscovery, ssr } = useFrameworkContext();
|
|
477
|
+
let { router, static: isStatic, staticContext } = useDataRouterContext();
|
|
478
|
+
let { matches: routerMatches } = useDataRouterStateContext();
|
|
479
|
+
let isRSCRouterContext = useIsRSCRouterContext();
|
|
480
|
+
let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
|
|
481
|
+
if (renderMeta) renderMeta.didRenderScripts = true;
|
|
482
|
+
let matches = getActiveMatches(routerMatches, null, isSpaMode);
|
|
483
|
+
React$1.useEffect(() => {
|
|
484
|
+
setIsHydrated();
|
|
485
|
+
}, []);
|
|
486
|
+
let initialScripts = React$1.useMemo(() => {
|
|
487
|
+
if (isRSCRouterContext) return null;
|
|
488
|
+
let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());` : " ";
|
|
489
|
+
let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
|
|
490
|
+
${matches.map((match, routeIndex) => {
|
|
491
|
+
let routeVarName = `route${routeIndex}`;
|
|
492
|
+
let manifestEntry = manifest.routes[match.route.id];
|
|
493
|
+
invariant(manifestEntry, `Route ${match.route.id} not found in manifest`);
|
|
494
|
+
let { clientActionModule, clientLoaderModule, clientMiddlewareModule, hydrateFallbackModule, module } = manifestEntry;
|
|
495
|
+
let chunks = [
|
|
496
|
+
...clientActionModule ? [{
|
|
497
|
+
module: clientActionModule,
|
|
498
|
+
varName: `${routeVarName}_clientAction`
|
|
499
|
+
}] : [],
|
|
500
|
+
...clientLoaderModule ? [{
|
|
501
|
+
module: clientLoaderModule,
|
|
502
|
+
varName: `${routeVarName}_clientLoader`
|
|
503
|
+
}] : [],
|
|
504
|
+
...clientMiddlewareModule ? [{
|
|
505
|
+
module: clientMiddlewareModule,
|
|
506
|
+
varName: `${routeVarName}_clientMiddleware`
|
|
507
|
+
}] : [],
|
|
508
|
+
...hydrateFallbackModule ? [{
|
|
509
|
+
module: hydrateFallbackModule,
|
|
510
|
+
varName: `${routeVarName}_HydrateFallback`
|
|
511
|
+
}] : [],
|
|
512
|
+
{
|
|
513
|
+
module,
|
|
514
|
+
varName: `${routeVarName}_main`
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
if (chunks.length === 1) return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
|
|
518
|
+
return [chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n"), `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`].join("\n");
|
|
519
|
+
}).join("\n")}
|
|
520
|
+
${enableFogOfWar ? `window.__reactRouterManifest = ${JSON.stringify(getPartialManifest(manifest, router), null, 2)};` : ""}
|
|
521
|
+
window.__reactRouterRouteModules = {${matches.map((match, index) => `${JSON.stringify(match.route.id)}:route${index}`).join(",")}};
|
|
522
|
+
|
|
523
|
+
import(${JSON.stringify(manifest.entry.module)});`;
|
|
524
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("script", {
|
|
525
|
+
...scriptProps,
|
|
526
|
+
suppressHydrationWarning: true,
|
|
527
|
+
dangerouslySetInnerHTML: { __html: contextScript },
|
|
528
|
+
type: void 0
|
|
529
|
+
}), /* @__PURE__ */ React$1.createElement("script", {
|
|
530
|
+
...scriptProps,
|
|
531
|
+
suppressHydrationWarning: true,
|
|
532
|
+
dangerouslySetInnerHTML: { __html: routeModulesScript },
|
|
533
|
+
type: "module",
|
|
534
|
+
async: true
|
|
535
|
+
}));
|
|
536
|
+
}, []);
|
|
537
|
+
let preloads = isHydrated || isRSCRouterContext ? [] : [...new Set(manifest.entry.imports.concat(getModuleLinkHrefs(matches, manifest, { includeHydrateFallback: true })))];
|
|
538
|
+
let sri = typeof manifest.sri === "object" ? manifest.sri : {};
|
|
539
|
+
warnOnce(!isRSCRouterContext, "The <Scripts /> element is a no-op when using RSC and can be safely removed.");
|
|
540
|
+
return isHydrated || isRSCRouterContext ? null : /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof manifest.sri === "object" ? /* @__PURE__ */ React$1.createElement("script", {
|
|
541
|
+
...scriptProps,
|
|
542
|
+
"rr-importmap": "",
|
|
543
|
+
type: "importmap",
|
|
544
|
+
suppressHydrationWarning: true,
|
|
545
|
+
dangerouslySetInnerHTML: { __html: JSON.stringify({ integrity: sri }) }
|
|
546
|
+
}) : null, !enableFogOfWar ? /* @__PURE__ */ React$1.createElement("link", {
|
|
547
|
+
rel: "modulepreload",
|
|
548
|
+
href: manifest.url,
|
|
549
|
+
crossOrigin: scriptProps.crossOrigin,
|
|
550
|
+
integrity: sri[manifest.url],
|
|
551
|
+
nonce: scriptProps.nonce,
|
|
552
|
+
suppressHydrationWarning: true
|
|
553
|
+
}) : null, /* @__PURE__ */ React$1.createElement("link", {
|
|
554
|
+
rel: "modulepreload",
|
|
555
|
+
href: manifest.entry.module,
|
|
556
|
+
crossOrigin: scriptProps.crossOrigin,
|
|
557
|
+
integrity: sri[manifest.entry.module],
|
|
558
|
+
nonce: scriptProps.nonce,
|
|
559
|
+
suppressHydrationWarning: true
|
|
560
|
+
}), preloads.map((path) => /* @__PURE__ */ React$1.createElement("link", {
|
|
561
|
+
key: path,
|
|
562
|
+
rel: "modulepreload",
|
|
563
|
+
href: path,
|
|
564
|
+
crossOrigin: scriptProps.crossOrigin,
|
|
565
|
+
integrity: sri[path],
|
|
566
|
+
nonce: scriptProps.nonce,
|
|
567
|
+
suppressHydrationWarning: true
|
|
568
|
+
})), initialScripts);
|
|
569
|
+
}
|
|
570
|
+
function mergeRefs(...refs) {
|
|
571
|
+
return (value) => {
|
|
572
|
+
refs.forEach((ref) => {
|
|
573
|
+
if (typeof ref === "function") ref(value);
|
|
574
|
+
else if (ref != null) ref.current = value;
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
//#endregion
|
|
579
|
+
export { CRITICAL_CSS_DATA_ATTRIBUTE, FrameworkContext, Links, Meta, PrefetchPageLinks, Scripts, mergeRefs, setIsHydrated, useFrameworkContext, usePrefetchBehavior };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#region lib/dom/ssr/data.ts
|
|
12
|
+
async function createRequestInit(request) {
|
|
13
|
+
let init = { signal: request.signal };
|
|
14
|
+
if (request.method !== "GET") {
|
|
15
|
+
init.method = request.method;
|
|
16
|
+
let contentType = request.headers.get("Content-Type");
|
|
17
|
+
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
18
|
+
init.headers = { "Content-Type": contentType };
|
|
19
|
+
init.body = JSON.stringify(await request.json());
|
|
20
|
+
} else if (contentType && /\btext\/plain\b/.test(contentType)) {
|
|
21
|
+
init.headers = { "Content-Type": contentType };
|
|
22
|
+
init.body = await request.text();
|
|
23
|
+
} else if (contentType && /\bapplication\/x-www-form-urlencoded\b/.test(contentType)) init.body = new URLSearchParams(await request.text());
|
|
24
|
+
else init.body = await request.formData();
|
|
25
|
+
}
|
|
26
|
+
return init;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createRequestInit };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
import { DataRouteObject, RouteBranch, RouteManifest } from "../../router/utils.js";
|
|
3
|
+
import { StaticHandlerContext } from "../../router/router.js";
|
|
4
|
+
import { RouteModules } from "./routeModules.js";
|
|
5
|
+
import { EntryRoute } from "./routes.js";
|
|
6
|
+
import { ServerBuild } from "../../server-runtime/build.js";
|
|
7
|
+
|
|
8
|
+
//#region lib/dom/ssr/entry.d.ts
|
|
9
|
+
type SerializedError = {
|
|
10
|
+
message: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
interface FrameworkContextObject {
|
|
14
|
+
manifest: AssetsManifest;
|
|
15
|
+
routeModules: RouteModules;
|
|
16
|
+
criticalCss?: CriticalCss;
|
|
17
|
+
serverHandoffString?: string;
|
|
18
|
+
future: FutureConfig;
|
|
19
|
+
ssr: boolean;
|
|
20
|
+
isSpaMode: boolean;
|
|
21
|
+
routeDiscovery: ServerBuild["routeDiscovery"];
|
|
22
|
+
serializeError?(error: Error): SerializedError;
|
|
23
|
+
renderMeta?: {
|
|
24
|
+
didRenderScripts?: boolean;
|
|
25
|
+
streamCache?: Record<number, Promise<void> & {
|
|
26
|
+
result?: {
|
|
27
|
+
done: boolean;
|
|
28
|
+
value: string;
|
|
29
|
+
};
|
|
30
|
+
error?: unknown;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface EntryContext extends FrameworkContextObject {
|
|
35
|
+
branches: RouteBranch<DataRouteObject>[];
|
|
36
|
+
staticHandlerContext: StaticHandlerContext;
|
|
37
|
+
serverHandoffStream?: ReadableStream<Uint8Array>;
|
|
38
|
+
}
|
|
39
|
+
type FutureConfig = Record<string, never>;
|
|
40
|
+
type CriticalCss = string | {
|
|
41
|
+
rel: "stylesheet";
|
|
42
|
+
href: string;
|
|
43
|
+
};
|
|
44
|
+
interface AssetsManifest {
|
|
45
|
+
entry: {
|
|
46
|
+
imports: string[];
|
|
47
|
+
module: string;
|
|
48
|
+
};
|
|
49
|
+
routes: RouteManifest<EntryRoute>;
|
|
50
|
+
url: string;
|
|
51
|
+
version: string;
|
|
52
|
+
hmr?: {
|
|
53
|
+
timestamp?: number;
|
|
54
|
+
runtime: string;
|
|
55
|
+
};
|
|
56
|
+
sri?: Record<string, string> | true;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { AssetsManifest, CriticalCss, EntryContext, FrameworkContextObject, FutureConfig };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { Location } from "../../router/history.js";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
|
|
5
|
+
//#region lib/dom/ssr/errorBoundaries.d.ts
|
|
6
|
+
type RemixErrorBoundaryProps = React$1.PropsWithChildren<{
|
|
7
|
+
location: Location;
|
|
8
|
+
isOutsideRemixApp?: boolean;
|
|
9
|
+
error?: Error;
|
|
10
|
+
}>;
|
|
11
|
+
type RemixErrorBoundaryState = {
|
|
12
|
+
error: null | Error;
|
|
13
|
+
location: Location;
|
|
14
|
+
};
|
|
15
|
+
declare class RemixErrorBoundary extends React$1.Component<RemixErrorBoundaryProps, RemixErrorBoundaryState> {
|
|
16
|
+
constructor(props: RemixErrorBoundaryProps);
|
|
17
|
+
static getDerivedStateFromError(error: Error): {
|
|
18
|
+
error: Error;
|
|
19
|
+
};
|
|
20
|
+
static getDerivedStateFromProps(props: RemixErrorBoundaryProps, state: RemixErrorBoundaryState): {
|
|
21
|
+
error: Error | null;
|
|
22
|
+
location: Location<any>;
|
|
23
|
+
};
|
|
24
|
+
render(): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | React$1.JSX.Element | null | undefined;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { RemixErrorBoundary };
|