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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { isRouteErrorResponse } from "../../router/utils.js";
|
|
12
|
+
import { Scripts, useFrameworkContext } from "./components.js";
|
|
13
|
+
import * as React$1 from "react";
|
|
14
|
+
//#region lib/dom/ssr/errorBoundaries.tsx
|
|
15
|
+
var RemixErrorBoundary = class extends React$1.Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
this.state = {
|
|
19
|
+
error: props.error || null,
|
|
20
|
+
location: props.location
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
static getDerivedStateFromError(error) {
|
|
24
|
+
return { error };
|
|
25
|
+
}
|
|
26
|
+
static getDerivedStateFromProps(props, state) {
|
|
27
|
+
if (state.location !== props.location) return {
|
|
28
|
+
error: props.error || null,
|
|
29
|
+
location: props.location
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
error: props.error || state.error,
|
|
33
|
+
location: state.location
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
if (this.state.error) return /* @__PURE__ */ React$1.createElement(RemixRootDefaultErrorBoundary, {
|
|
38
|
+
error: this.state.error,
|
|
39
|
+
isOutsideRemixApp: true
|
|
40
|
+
});
|
|
41
|
+
else return this.props.children;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* When app's don't provide a root level ErrorBoundary, we default to this.
|
|
46
|
+
*/
|
|
47
|
+
function RemixRootDefaultErrorBoundary({ error, isOutsideRemixApp }) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
let heyDeveloper = /* @__PURE__ */ React$1.createElement("script", { dangerouslySetInnerHTML: { __html: `
|
|
50
|
+
console.log(
|
|
51
|
+
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
|
|
52
|
+
);
|
|
53
|
+
` } });
|
|
54
|
+
if (isRouteErrorResponse(error)) return /* @__PURE__ */ React$1.createElement(BoundaryShell, { title: "Unhandled Thrown Response!" }, /* @__PURE__ */ React$1.createElement("h1", { style: { fontSize: "24px" } }, error.status, " ", error.statusText), heyDeveloper);
|
|
55
|
+
let errorInstance;
|
|
56
|
+
if (error instanceof Error) errorInstance = error;
|
|
57
|
+
else {
|
|
58
|
+
let errorString = error == null ? "Unknown Error" : typeof error === "object" && "toString" in error ? error.toString() : JSON.stringify(error);
|
|
59
|
+
errorInstance = new Error(errorString);
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ React$1.createElement(BoundaryShell, {
|
|
62
|
+
title: "Application Error!",
|
|
63
|
+
isOutsideRemixApp
|
|
64
|
+
}, /* @__PURE__ */ React$1.createElement("h1", { style: { fontSize: "24px" } }, "Application Error"), /* @__PURE__ */ React$1.createElement("pre", { style: {
|
|
65
|
+
padding: "2rem",
|
|
66
|
+
background: "hsla(10, 50%, 50%, 0.1)",
|
|
67
|
+
color: "red",
|
|
68
|
+
overflow: "auto"
|
|
69
|
+
} }, errorInstance.stack), heyDeveloper);
|
|
70
|
+
}
|
|
71
|
+
function BoundaryShell({ title, renderScripts, isOutsideRemixApp, children }) {
|
|
72
|
+
let { routeModules } = useFrameworkContext();
|
|
73
|
+
if (routeModules.root?.Layout && !isOutsideRemixApp) return children;
|
|
74
|
+
return /* @__PURE__ */ React$1.createElement("html", { lang: "en" }, /* @__PURE__ */ React$1.createElement("head", null, /* @__PURE__ */ React$1.createElement("meta", { charSet: "utf-8" }), /* @__PURE__ */ React$1.createElement("meta", {
|
|
75
|
+
name: "viewport",
|
|
76
|
+
content: "width=device-width,initial-scale=1,viewport-fit=cover"
|
|
77
|
+
}), /* @__PURE__ */ React$1.createElement("title", null, title)), /* @__PURE__ */ React$1.createElement("body", null, /* @__PURE__ */ React$1.createElement("main", { style: {
|
|
78
|
+
fontFamily: "system-ui, sans-serif",
|
|
79
|
+
padding: "2rem"
|
|
80
|
+
} }, children, renderScripts ? /* @__PURE__ */ React$1.createElement(Scripts, null) : null)));
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { BoundaryShell, RemixErrorBoundary, RemixRootDefaultErrorBoundary };
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { ErrorResponseImpl } from "../../router/utils.js";
|
|
12
|
+
//#region lib/dom/ssr/errors.ts
|
|
13
|
+
function deserializeErrors(errors) {
|
|
14
|
+
if (!errors) return null;
|
|
15
|
+
let entries = Object.entries(errors);
|
|
16
|
+
let serialized = {};
|
|
17
|
+
for (let [key, val] of entries) if (val && val.__type === "RouteErrorResponse") serialized[key] = new ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true);
|
|
18
|
+
else if (val && val.__type === "Error") {
|
|
19
|
+
if (val.__subType) {
|
|
20
|
+
let ErrorConstructor = window[val.__subType];
|
|
21
|
+
if (typeof ErrorConstructor === "function") try {
|
|
22
|
+
let error = new ErrorConstructor(val.message);
|
|
23
|
+
error.stack = val.stack;
|
|
24
|
+
serialized[key] = error;
|
|
25
|
+
} catch (e) {}
|
|
26
|
+
}
|
|
27
|
+
if (serialized[key] == null) {
|
|
28
|
+
let error = new Error(val.message);
|
|
29
|
+
error.stack = val.stack;
|
|
30
|
+
serialized[key] = error;
|
|
31
|
+
}
|
|
32
|
+
} else serialized[key] = val;
|
|
33
|
+
return serialized;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { deserializeErrors };
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { BoundaryShell } from "./errorBoundaries.js";
|
|
12
|
+
import * as React$1 from "react";
|
|
13
|
+
//#region lib/dom/ssr/fallback.tsx
|
|
14
|
+
function RemixRootDefaultHydrateFallback() {
|
|
15
|
+
return /* @__PURE__ */ React$1.createElement(BoundaryShell, {
|
|
16
|
+
title: "Loading...",
|
|
17
|
+
renderScripts: true
|
|
18
|
+
}, /* @__PURE__ */ React$1.createElement("script", { dangerouslySetInnerHTML: { __html: `
|
|
19
|
+
console.log(
|
|
20
|
+
"💿 Hey developer 👋. You can provide a way better UX than this " +
|
|
21
|
+
"when your app is loading JS modules and/or running \`clientLoader\` " +
|
|
22
|
+
"functions. Check out https://reactrouter.com/start/framework/route-module#hydratefallback " +
|
|
23
|
+
"for more information."
|
|
24
|
+
);
|
|
25
|
+
` } }));
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { RemixRootDefaultHydrateFallback };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import { PatchRoutesOnNavigationFunction } from "../../router/utils.js";
|
|
3
|
+
import { Router } from "../../router/router.js";
|
|
4
|
+
import { RouteModules } from "./routeModules.js";
|
|
5
|
+
import { AssetsManifest } from "./entry.js";
|
|
6
|
+
import { ServerBuild } from "../../server-runtime/build.js";
|
|
7
|
+
|
|
8
|
+
//#region lib/dom/ssr/fog-of-war.d.ts
|
|
9
|
+
declare function getPatchRoutesOnNavigationFunction(getRouter: () => Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean, basename: string | undefined): PatchRoutesOnNavigationFunction | undefined;
|
|
10
|
+
declare function useFogOFWarDiscovery(router: Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean): void;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getPatchRoutesOnNavigationFunction, useFogOFWarDiscovery };
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { createPath } from "../../router/history.js";
|
|
12
|
+
import { joinPaths, matchRoutesImpl } from "../../router/utils.js";
|
|
13
|
+
import { createClientRoutes } from "./routes.js";
|
|
14
|
+
import * as React$1 from "react";
|
|
15
|
+
//#region lib/dom/ssr/fog-of-war.ts
|
|
16
|
+
const nextPaths = /* @__PURE__ */ new Set();
|
|
17
|
+
const discoveredPathsMaxSize = 1e3;
|
|
18
|
+
const discoveredPaths = /* @__PURE__ */ new Set();
|
|
19
|
+
const URL_LIMIT = 7680;
|
|
20
|
+
function isFogOfWarEnabled(routeDiscovery, ssr) {
|
|
21
|
+
return routeDiscovery.mode === "lazy" && ssr === true;
|
|
22
|
+
}
|
|
23
|
+
function getPartialManifest({ sri, ...manifest }, router) {
|
|
24
|
+
let routeIds = new Set(router.state.matches.map((m) => m.route.id));
|
|
25
|
+
let segments = router.state.location.pathname.split("/").filter(Boolean);
|
|
26
|
+
let paths = ["/"];
|
|
27
|
+
segments.pop();
|
|
28
|
+
while (segments.length > 0) {
|
|
29
|
+
paths.push(`/${segments.join("/")}`);
|
|
30
|
+
segments.pop();
|
|
31
|
+
}
|
|
32
|
+
paths.forEach((path) => {
|
|
33
|
+
let matches = matchRoutesImpl(router.routes, path, router.basename || "/", false, router.branches);
|
|
34
|
+
if (matches) matches.forEach((m) => routeIds.add(m.route.id));
|
|
35
|
+
});
|
|
36
|
+
let initialRoutes = [...routeIds].reduce((acc, id) => Object.assign(acc, { [id]: manifest.routes[id] }), {});
|
|
37
|
+
return {
|
|
38
|
+
...manifest,
|
|
39
|
+
routes: initialRoutes,
|
|
40
|
+
sri: sri ? true : void 0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getPatchRoutesOnNavigationFunction(getRouter, manifest, routeModules, ssr, routeDiscovery, isSpaMode, basename) {
|
|
44
|
+
if (!isFogOfWarEnabled(routeDiscovery, ssr)) return;
|
|
45
|
+
return async ({ path, patch, signal, fetcherKey }) => {
|
|
46
|
+
if (discoveredPaths.has(path)) return;
|
|
47
|
+
let { state } = getRouter();
|
|
48
|
+
await fetchAndApplyManifestPatches([path], fetcherKey ? window.location.href : createPath(state.navigation.location || state.location), manifest, routeModules, ssr, isSpaMode, basename, routeDiscovery.manifestPath, patch, signal);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode) {
|
|
52
|
+
React$1.useEffect(() => {
|
|
53
|
+
if (!isFogOfWarEnabled(routeDiscovery, ssr) || window.navigator?.connection?.saveData === true) return;
|
|
54
|
+
function registerElement(el) {
|
|
55
|
+
let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
|
56
|
+
if (!path) return;
|
|
57
|
+
let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
|
58
|
+
if (!discoveredPaths.has(pathname)) nextPaths.add(pathname);
|
|
59
|
+
}
|
|
60
|
+
async function fetchPatches() {
|
|
61
|
+
document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
|
62
|
+
let lazyPaths = Array.from(nextPaths.keys()).filter((path) => {
|
|
63
|
+
if (discoveredPaths.has(path)) {
|
|
64
|
+
nextPaths.delete(path);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
if (lazyPaths.length === 0) return;
|
|
70
|
+
try {
|
|
71
|
+
await fetchAndApplyManifestPatches(lazyPaths, null, manifest, routeModules, ssr, isSpaMode, router.basename, routeDiscovery.manifestPath, router.patchRoutes);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error("Failed to fetch manifest patches", e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let debouncedFetchPatches = debounce(fetchPatches, 100);
|
|
77
|
+
fetchPatches();
|
|
78
|
+
let observer = new MutationObserver(() => debouncedFetchPatches());
|
|
79
|
+
observer.observe(document.documentElement, {
|
|
80
|
+
subtree: true,
|
|
81
|
+
childList: true,
|
|
82
|
+
attributes: true,
|
|
83
|
+
attributeFilter: [
|
|
84
|
+
"data-discover",
|
|
85
|
+
"href",
|
|
86
|
+
"action"
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
return () => observer.disconnect();
|
|
90
|
+
}, [
|
|
91
|
+
ssr,
|
|
92
|
+
isSpaMode,
|
|
93
|
+
manifest,
|
|
94
|
+
routeModules,
|
|
95
|
+
router,
|
|
96
|
+
routeDiscovery
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
function getManifestPath(_manifestPath, basename) {
|
|
100
|
+
let manifestPath = _manifestPath || "/__manifest";
|
|
101
|
+
return basename == null ? manifestPath : joinPaths([basename, manifestPath]);
|
|
102
|
+
}
|
|
103
|
+
const MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
|
|
104
|
+
async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
|
|
105
|
+
const searchParams = new URLSearchParams();
|
|
106
|
+
searchParams.set("paths", paths.sort().join(","));
|
|
107
|
+
searchParams.set("version", manifest.version);
|
|
108
|
+
let url = new URL(getManifestPath(manifestPath, basename), window.location.origin);
|
|
109
|
+
url.search = searchParams.toString();
|
|
110
|
+
if (url.toString().length > 7680) {
|
|
111
|
+
nextPaths.clear();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let serverPatches;
|
|
115
|
+
try {
|
|
116
|
+
let res = await fetch(url, { signal });
|
|
117
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
118
|
+
else if (res.status === 204 && res.headers.has("X-Remix-Reload-Document")) {
|
|
119
|
+
if (!errorReloadPath) {
|
|
120
|
+
console.warn("Detected a manifest version mismatch during eager route discovery. The next navigation/fetch to an undiscovered route will result in a new document navigation to sync up with the latest manifest.");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
if (sessionStorage.getItem(MANIFEST_VERSION_STORAGE_KEY) === manifest.version) {
|
|
125
|
+
console.error("Unable to discover routes due to manifest version mismatch.");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, manifest.version);
|
|
129
|
+
} catch {}
|
|
130
|
+
window.location.href = errorReloadPath;
|
|
131
|
+
console.warn("Detected manifest version mismatch, reloading...");
|
|
132
|
+
await new Promise(() => {});
|
|
133
|
+
} else if (res.status >= 400) throw new Error(await res.text());
|
|
134
|
+
try {
|
|
135
|
+
sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
|
|
136
|
+
} catch {}
|
|
137
|
+
serverPatches = await res.json();
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (signal?.aborted) return;
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
let knownRoutes = new Set(Object.keys(manifest.routes));
|
|
143
|
+
let patches = Object.values(serverPatches).reduce((acc, route) => {
|
|
144
|
+
if (route && !knownRoutes.has(route.id)) acc[route.id] = route;
|
|
145
|
+
return acc;
|
|
146
|
+
}, {});
|
|
147
|
+
Object.assign(manifest.routes, patches);
|
|
148
|
+
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
149
|
+
let parentIds = /* @__PURE__ */ new Set();
|
|
150
|
+
Object.values(patches).forEach((patch) => {
|
|
151
|
+
if (patch && (!patch.parentId || !patches[patch.parentId])) parentIds.add(patch.parentId);
|
|
152
|
+
});
|
|
153
|
+
parentIds.forEach((parentId) => patchRoutes(parentId || null, createClientRoutes(patches, routeModules, null, ssr, isSpaMode, parentId)));
|
|
154
|
+
}
|
|
155
|
+
function addToFifoQueue(path, queue) {
|
|
156
|
+
if (queue.size >= discoveredPathsMaxSize) {
|
|
157
|
+
let first = queue.values().next().value;
|
|
158
|
+
if (first !== void 0) queue.delete(first);
|
|
159
|
+
}
|
|
160
|
+
queue.add(path);
|
|
161
|
+
}
|
|
162
|
+
function debounce(callback, wait) {
|
|
163
|
+
let timeoutId;
|
|
164
|
+
return (...args) => {
|
|
165
|
+
window.clearTimeout(timeoutId);
|
|
166
|
+
timeoutId = window.setTimeout(() => callback(...args), wait);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
export { URL_LIMIT, getManifestPath, getPartialManifest, getPatchRoutesOnNavigationFunction, isFogOfWarEnabled, useFogOFWarDiscovery };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import { Path } from "../../router/history.js";
|
|
3
|
+
import { DataRouteObject } from "../../router/utils.js";
|
|
4
|
+
import { HydrationState, Router } from "../../router/router.js";
|
|
5
|
+
import { ClientLoaderFunction } from "./routeModules.js";
|
|
6
|
+
|
|
7
|
+
//#region lib/dom/ssr/hydration.d.ts
|
|
8
|
+
declare function getHydrationData({
|
|
9
|
+
state,
|
|
10
|
+
routes,
|
|
11
|
+
getRouteInfo,
|
|
12
|
+
location,
|
|
13
|
+
basename,
|
|
14
|
+
isSpaMode
|
|
15
|
+
}: {
|
|
16
|
+
state: {
|
|
17
|
+
loaderData?: Router["state"]["loaderData"];
|
|
18
|
+
actionData?: Router["state"]["actionData"];
|
|
19
|
+
errors?: Router["state"]["errors"];
|
|
20
|
+
};
|
|
21
|
+
routes: DataRouteObject[];
|
|
22
|
+
getRouteInfo: (routeId: string) => {
|
|
23
|
+
clientLoader: ClientLoaderFunction | undefined;
|
|
24
|
+
hasLoader: boolean;
|
|
25
|
+
hasHydrateFallback: boolean;
|
|
26
|
+
};
|
|
27
|
+
location: Path;
|
|
28
|
+
basename: string | undefined;
|
|
29
|
+
isSpaMode: boolean;
|
|
30
|
+
}): HydrationState;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getHydrationData };
|
|
@@ -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
|
+
import { matchRoutes } from "../../router/utils.js";
|
|
12
|
+
import { shouldHydrateRouteLoader } from "./routes.js";
|
|
13
|
+
//#region lib/dom/ssr/hydration.tsx
|
|
14
|
+
function getHydrationData({ state, routes, getRouteInfo, location, basename, isSpaMode }) {
|
|
15
|
+
let hydrationData = {
|
|
16
|
+
...state,
|
|
17
|
+
loaderData: { ...state.loaderData }
|
|
18
|
+
};
|
|
19
|
+
let initialMatches = matchRoutes(routes, location, basename);
|
|
20
|
+
if (initialMatches) for (let match of initialMatches) {
|
|
21
|
+
let routeId = match.route.id;
|
|
22
|
+
let routeInfo = getRouteInfo(routeId);
|
|
23
|
+
if (shouldHydrateRouteLoader(routeId, routeInfo.clientLoader, routeInfo.hasLoader, isSpaMode) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) delete hydrationData.loaderData[routeId];
|
|
24
|
+
else if (!routeInfo.hasLoader) hydrationData.loaderData[routeId] = null;
|
|
25
|
+
}
|
|
26
|
+
return hydrationData;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getHydrationData };
|
|
@@ -0,0 +1,16 @@
|
|
|
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/invariant.ts
|
|
12
|
+
function invariant(value, message) {
|
|
13
|
+
if (value === false || value === null || typeof value === "undefined") throw new Error(message);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { invariant as default };
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { loadRouteModule } from "./routeModules.js";
|
|
12
|
+
//#region lib/dom/ssr/links.ts
|
|
13
|
+
/**
|
|
14
|
+
* Gets all the links for a set of matches. The modules are assumed to have been
|
|
15
|
+
* loaded already.
|
|
16
|
+
*/
|
|
17
|
+
function getKeyedLinksForMatches(matches, routeModules, manifest) {
|
|
18
|
+
return dedupeLinkDescriptors(matches.map((match) => {
|
|
19
|
+
let module = routeModules[match.route.id];
|
|
20
|
+
let route = manifest.routes[match.route.id];
|
|
21
|
+
return [route && route.css ? route.css.map((href) => ({
|
|
22
|
+
rel: "stylesheet",
|
|
23
|
+
href
|
|
24
|
+
})) : [], module?.links?.() || []];
|
|
25
|
+
}).flat(2), getModuleLinkHrefs(matches, manifest));
|
|
26
|
+
}
|
|
27
|
+
function getRouteCssDescriptors(route) {
|
|
28
|
+
if (!route.css) return [];
|
|
29
|
+
return route.css.map((href) => ({
|
|
30
|
+
rel: "stylesheet",
|
|
31
|
+
href
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
async function prefetchRouteCss(route) {
|
|
35
|
+
if (!route.css) return;
|
|
36
|
+
let descriptors = getRouteCssDescriptors(route);
|
|
37
|
+
await Promise.all(descriptors.map(prefetchStyleLink));
|
|
38
|
+
}
|
|
39
|
+
async function prefetchStyleLinks(route, routeModule) {
|
|
40
|
+
if (!route.css && !routeModule.links || !isPreloadSupported()) return;
|
|
41
|
+
let descriptors = [];
|
|
42
|
+
if (route.css) descriptors.push(...getRouteCssDescriptors(route));
|
|
43
|
+
if (routeModule.links) descriptors.push(...routeModule.links());
|
|
44
|
+
if (descriptors.length === 0) return;
|
|
45
|
+
let styleLinks = [];
|
|
46
|
+
for (let descriptor of descriptors) if (!isPageLinkDescriptor(descriptor) && descriptor.rel === "stylesheet") styleLinks.push({
|
|
47
|
+
...descriptor,
|
|
48
|
+
rel: "preload",
|
|
49
|
+
as: "style"
|
|
50
|
+
});
|
|
51
|
+
await Promise.all(styleLinks.map(prefetchStyleLink));
|
|
52
|
+
}
|
|
53
|
+
async function prefetchStyleLink(descriptor) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
if (descriptor.media && !window.matchMedia(descriptor.media).matches || document.querySelector(`link[rel="stylesheet"][href="${descriptor.href}"]`)) return resolve();
|
|
56
|
+
let link = document.createElement("link");
|
|
57
|
+
Object.assign(link, descriptor);
|
|
58
|
+
function removeLink() {
|
|
59
|
+
if (document.head.contains(link)) document.head.removeChild(link);
|
|
60
|
+
}
|
|
61
|
+
link.onload = () => {
|
|
62
|
+
removeLink();
|
|
63
|
+
resolve();
|
|
64
|
+
};
|
|
65
|
+
link.onerror = () => {
|
|
66
|
+
removeLink();
|
|
67
|
+
resolve();
|
|
68
|
+
};
|
|
69
|
+
document.head.appendChild(link);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function isPageLinkDescriptor(object) {
|
|
73
|
+
return object != null && typeof object.page === "string";
|
|
74
|
+
}
|
|
75
|
+
function isHtmlLinkDescriptor(object) {
|
|
76
|
+
if (object == null) return false;
|
|
77
|
+
if (object.href == null) return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
|
|
78
|
+
return typeof object.rel === "string" && typeof object.href === "string";
|
|
79
|
+
}
|
|
80
|
+
async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
|
|
81
|
+
return dedupeLinkDescriptors((await Promise.all(matches.map(async (match) => {
|
|
82
|
+
let route = manifest.routes[match.route.id];
|
|
83
|
+
if (route) {
|
|
84
|
+
let mod = await loadRouteModule(route, routeModules);
|
|
85
|
+
return mod.links ? mod.links() : [];
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
}))).flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map((link) => link.rel === "stylesheet" ? {
|
|
89
|
+
...link,
|
|
90
|
+
rel: "prefetch",
|
|
91
|
+
as: "style"
|
|
92
|
+
} : {
|
|
93
|
+
...link,
|
|
94
|
+
rel: "prefetch"
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
|
|
98
|
+
let isNew = (match, index) => {
|
|
99
|
+
if (!currentMatches[index]) return true;
|
|
100
|
+
return match.route.id !== currentMatches[index].route.id;
|
|
101
|
+
};
|
|
102
|
+
let matchPathChanged = (match, index) => {
|
|
103
|
+
return currentMatches[index].pathname !== match.pathname || currentMatches[index].route.path?.endsWith("*") && currentMatches[index].params["*"] !== match.params["*"];
|
|
104
|
+
};
|
|
105
|
+
if (mode === "assets") return nextMatches.filter((match, index) => isNew(match, index) || matchPathChanged(match, index));
|
|
106
|
+
if (mode === "data") return nextMatches.filter((match, index) => {
|
|
107
|
+
let manifestRoute = manifest.routes[match.route.id];
|
|
108
|
+
if (!manifestRoute || !manifestRoute.hasLoader) return false;
|
|
109
|
+
if (isNew(match, index) || matchPathChanged(match, index)) return true;
|
|
110
|
+
if (match.route.shouldRevalidate) {
|
|
111
|
+
let routeChoice = match.route.shouldRevalidate({
|
|
112
|
+
currentUrl: new URL(location.pathname + location.search + location.hash, window.origin),
|
|
113
|
+
currentParams: currentMatches[0]?.params || {},
|
|
114
|
+
nextUrl: new URL(page, window.origin),
|
|
115
|
+
nextParams: match.params,
|
|
116
|
+
defaultShouldRevalidate: true
|
|
117
|
+
});
|
|
118
|
+
if (typeof routeChoice === "boolean") return routeChoice;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
|
|
125
|
+
return dedupeHrefs(matches.map((match) => {
|
|
126
|
+
let route = manifest.routes[match.route.id];
|
|
127
|
+
if (!route) return [];
|
|
128
|
+
let hrefs = [route.module];
|
|
129
|
+
if (route.clientActionModule) hrefs = hrefs.concat(route.clientActionModule);
|
|
130
|
+
if (route.clientLoaderModule) hrefs = hrefs.concat(route.clientLoaderModule);
|
|
131
|
+
if (includeHydrateFallback && route.hydrateFallbackModule) hrefs = hrefs.concat(route.hydrateFallbackModule);
|
|
132
|
+
if (route.imports) hrefs = hrefs.concat(route.imports);
|
|
133
|
+
return hrefs;
|
|
134
|
+
}).flat(1));
|
|
135
|
+
}
|
|
136
|
+
function dedupeHrefs(hrefs) {
|
|
137
|
+
return [...new Set(hrefs)];
|
|
138
|
+
}
|
|
139
|
+
function sortKeys(obj) {
|
|
140
|
+
let sorted = {};
|
|
141
|
+
let keys = Object.keys(obj).sort();
|
|
142
|
+
for (let key of keys) sorted[key] = obj[key];
|
|
143
|
+
return sorted;
|
|
144
|
+
}
|
|
145
|
+
function dedupeLinkDescriptors(descriptors, preloads) {
|
|
146
|
+
let set = /* @__PURE__ */ new Set();
|
|
147
|
+
let preloadsSet = new Set(preloads);
|
|
148
|
+
return descriptors.reduce((deduped, descriptor) => {
|
|
149
|
+
if (preloads && !isPageLinkDescriptor(descriptor) && descriptor.as === "script" && descriptor.href && preloadsSet.has(descriptor.href)) return deduped;
|
|
150
|
+
let key = JSON.stringify(sortKeys(descriptor));
|
|
151
|
+
if (!set.has(key)) {
|
|
152
|
+
set.add(key);
|
|
153
|
+
deduped.push({
|
|
154
|
+
key,
|
|
155
|
+
link: descriptor
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return deduped;
|
|
159
|
+
}, []);
|
|
160
|
+
}
|
|
161
|
+
let _isPreloadSupported;
|
|
162
|
+
function isPreloadSupported() {
|
|
163
|
+
if (_isPreloadSupported !== void 0) return _isPreloadSupported;
|
|
164
|
+
let el = document.createElement("link");
|
|
165
|
+
_isPreloadSupported = el.relList.supports("preload");
|
|
166
|
+
el = null;
|
|
167
|
+
return _isPreloadSupported;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
export { getKeyedLinksForMatches, getKeyedPrefetchLinks, getModuleLinkHrefs, getNewMatchesForLinks, isPageLinkDescriptor, prefetchRouteCss, prefetchStyleLinks };
|
|
@@ -0,0 +1,24 @@
|
|
|
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/markup.ts
|
|
12
|
+
const ESCAPE_LOOKUP = {
|
|
13
|
+
"&": "\\u0026",
|
|
14
|
+
">": "\\u003e",
|
|
15
|
+
"<": "\\u003c",
|
|
16
|
+
"\u2028": "\\u2028",
|
|
17
|
+
"\u2029": "\\u2029"
|
|
18
|
+
};
|
|
19
|
+
const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
20
|
+
function escapeHtml(html) {
|
|
21
|
+
return html.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { escapeHtml };
|