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,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Progressive Enhancement
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Progressive Enhancement
|
|
6
|
+
|
|
7
|
+
[MODES: framework]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
> Progressive enhancement is a strategy in web design that puts emphasis on web content first, allowing everyone to access the basic content and functionality of a web page, whilst users with additional browser features or faster Internet access receive the enhanced version instead.
|
|
13
|
+
>
|
|
14
|
+
> <cite>- [Wikipedia][wikipedia]</cite>
|
|
15
|
+
|
|
16
|
+
When using React Router with Server-Side Rendering (the default in framework mode), you can automatically leverage the benefits of progressive enhancement.
|
|
17
|
+
|
|
18
|
+
## Why Progressive Enhancement Matters
|
|
19
|
+
|
|
20
|
+
Coined in 2003 by Steven Champeon & Nick Finck, the phrase emerged during a time of varied CSS and JavaScript support across different browsers, with many users actually browsing the web with JavaScript disabled.
|
|
21
|
+
|
|
22
|
+
Today, we are fortunate to develop for a much more consistent web and where the majority of users have JavaScript enabled.
|
|
23
|
+
|
|
24
|
+
However, we still believe in the core principles of progressive enhancement in React Router. It leads to fast and resilient apps with simple development workflows.
|
|
25
|
+
|
|
26
|
+
**Performance**: While it's easy to think that only 5% of your users have slow connections, the reality is that 100% of your users have slow connections 5% of the time.
|
|
27
|
+
|
|
28
|
+
**Resilience**: Everybody has JavaScript disabled until it's loaded.
|
|
29
|
+
|
|
30
|
+
**Simplicity**: Building your apps in a progressively enhanced way with React Router is actually simpler than building a traditional SPA.
|
|
31
|
+
|
|
32
|
+
## Performance
|
|
33
|
+
|
|
34
|
+
Server rendering allows your app to do more things in parallel than a typical [Single Page App (SPA)][spa], making the initial loading experience and subsequent navigations faster.
|
|
35
|
+
|
|
36
|
+
Typical SPAs send a blank document and only start doing work when JavaScript has loaded:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
HTML |---|
|
|
40
|
+
JavaScript |---------|
|
|
41
|
+
Data |---------------|
|
|
42
|
+
page rendered 👆
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A React Router app can start doing work the moment the request hits the server and stream the response so that the browser can start downloading JavaScript, other assets, and data in parallel:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
👇 first byte
|
|
49
|
+
HTML |---|-----------|
|
|
50
|
+
JavaScript |---------|
|
|
51
|
+
Data |---------------|
|
|
52
|
+
page rendered 👆
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Resilience and Accessibility
|
|
56
|
+
|
|
57
|
+
While your users probably don't browse the web with JavaScript disabled, everybody uses the websites without JavaScript before it finishes loading. React Router embraces progressive enhancement by building on top of HTML, allowing you to build your app in a way that works without JavaScript, and then layer on JavaScript to enhance the experience.
|
|
58
|
+
|
|
59
|
+
The simplest case is a `<Link to="/account">`. These render an `<a href="/account">` tag that works without JavaScript. When JavaScript loads, React Router will intercept clicks and handle the navigation with client side routing. This gives you more control over the UX instead of just spinning favicons in the browser tab--but it works either way.
|
|
60
|
+
|
|
61
|
+
Now consider a simple add to cart button:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
export function AddToCart({ id }) {
|
|
65
|
+
return (
|
|
66
|
+
<Form method="post" action="/add-to-cart">
|
|
67
|
+
<input type="hidden" name="id" value={id} />
|
|
68
|
+
<button type="submit">Add To Cart</button>
|
|
69
|
+
</Form>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Whether JavaScript has loaded or not doesn't matter, this button will add the product to the cart.
|
|
75
|
+
|
|
76
|
+
When JavaScript loads, React Router will intercept the form submission and handle it client side. This allows you to add your own pending UI, or other client side behavior.
|
|
77
|
+
|
|
78
|
+
## Simplicity
|
|
79
|
+
|
|
80
|
+
When you start to rely on basic features of the web like HTML and URLs, you will find that you reach for client side state and state management much less.
|
|
81
|
+
|
|
82
|
+
Consider the button from before, with no fundamental change to the code, we can pepper in some client side behavior:
|
|
83
|
+
|
|
84
|
+
```tsx lines=[1,4,7,10-12,14]
|
|
85
|
+
import { useFetcher } from "react-router";
|
|
86
|
+
|
|
87
|
+
export function AddToCart({ id }) {
|
|
88
|
+
const fetcher = useFetcher();
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<fetcher.Form method="post" action="/add-to-cart">
|
|
92
|
+
<input name="id" value={id} />
|
|
93
|
+
<button type="submit">
|
|
94
|
+
{fetcher.state === "submitting"
|
|
95
|
+
? "Adding..."
|
|
96
|
+
: "Add To Cart"}
|
|
97
|
+
</button>
|
|
98
|
+
</fetcher.Form>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This feature continues to work the very same as it did before when JavaScript is loading, but once JavaScript loads:
|
|
104
|
+
|
|
105
|
+
- `useFetcher` no longer causes a navigation like `<Form>` does, so the user can stay on the same page and keep shopping
|
|
106
|
+
- The app code determines the pending UI instead of spinning favicons in the browser
|
|
107
|
+
|
|
108
|
+
It's not about building it two different ways–once for JavaScript and once without–it's about building it in iterations. Start with the simplest version of the feature and ship it; then iterate to an enhanced user experience.
|
|
109
|
+
|
|
110
|
+
Not only will the user get a progressively enhanced experience, but the app developer gets to "progressively enhance" the UI without changing the fundamental design of the feature.
|
|
111
|
+
|
|
112
|
+
Another example where progressive enhancement leads to simplicity is with the URL. When you start with a URL, you don't need to worry about client side state management. You can just use the URL as the source of truth for the UI.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
export function SearchBox() {
|
|
116
|
+
return (
|
|
117
|
+
<Form method="get" action="/search">
|
|
118
|
+
<input type="search" name="query" />
|
|
119
|
+
<SearchIcon />
|
|
120
|
+
</Form>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
This component doesn't need any state management. It just renders a form that submits to `/search`. When JavaScript loads, React Router will intercept the form submission and handle it client side. Here's the next iteration:
|
|
126
|
+
|
|
127
|
+
```tsx lines=[1,4-6,11]
|
|
128
|
+
import { useNavigation } from "react-router";
|
|
129
|
+
|
|
130
|
+
export function SearchBox() {
|
|
131
|
+
const navigation = useNavigation();
|
|
132
|
+
const isSearching =
|
|
133
|
+
navigation.location.pathname === "/search";
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Form method="get" action="/search">
|
|
137
|
+
<input type="search" name="query" />
|
|
138
|
+
{isSearching ? <Spinner /> : <SearchIcon />}
|
|
139
|
+
</Form>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
No fundamental change in architecture, simply a progressive enhancement for both the user and the code.
|
|
145
|
+
|
|
146
|
+
See also: [State Management][state_management]
|
|
147
|
+
|
|
148
|
+
[wikipedia]: https://en.wikipedia.org/wiki/Progressive_enhancement
|
|
149
|
+
[spa]: ../how-to/spa
|
|
150
|
+
[state_management]: ./state-management
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Race Conditions
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Race Conditions
|
|
6
|
+
|
|
7
|
+
[MODES: framework, data]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
While impossible to eliminate every possible race condition in your application, React Router automatically handles the most common race conditions found in web user interfaces.
|
|
13
|
+
|
|
14
|
+
## Browser Behavior
|
|
15
|
+
|
|
16
|
+
React Router's handling of network concurrency is heavily inspired by the behavior of web browsers when processing documents.
|
|
17
|
+
|
|
18
|
+
Consider clicking a link to a new document, and then clicking a different link before the new page has finished loading. The browser will:
|
|
19
|
+
|
|
20
|
+
1. cancel the first request
|
|
21
|
+
2. immediately process the new navigation
|
|
22
|
+
|
|
23
|
+
The same behavior applies to form submissions. When a pending form submission is interrupted by a new one, the first is canceled and the new submission is immediately processed.
|
|
24
|
+
|
|
25
|
+
## React Router Behavior
|
|
26
|
+
|
|
27
|
+
Like the browser, interrupted navigations with links and form submissions will cancel in flight data requests and immediately process the new event.
|
|
28
|
+
|
|
29
|
+
Fetchers are a bit more nuanced since they are not singleton events like navigation. Fetchers can't interrupt other fetcher instances, but they can interrupt themselves and the behavior is the same as everything else: cancel the interrupted request and immediately process the new one.
|
|
30
|
+
|
|
31
|
+
Fetchers do, however, interact with each other when it comes to revalidation. After a fetcher's action request returns to the browser, a revalidation for all page data is sent. This means multiple revalidation requests can be in-flight at the same time. React Router will commit all "fresh" revalidation responses and cancel any stale requests. A stale request is any request that started _earlier_ than one that has returned.
|
|
32
|
+
|
|
33
|
+
This management of the network prevents the most common UI bugs caused by network race conditions.
|
|
34
|
+
|
|
35
|
+
Since networks are unpredictable, and your server still processes these cancelled requests, your backend may still experience race conditions and have potential data integrity issues. These risks are the same risks as using default browser behavior with plain HTML `<forms>`, which we consider to be low, and outside the scope of React Router.
|
|
36
|
+
|
|
37
|
+
## Practical Benefits
|
|
38
|
+
|
|
39
|
+
Consider building a type-ahead combobox. As the user types, you send a request to the server. As they type each new character you send a new request. It's important to not show the user results for a value that's not in the text field anymore.
|
|
40
|
+
|
|
41
|
+
When using a fetcher, this is automatically managed for you. Consider this pseudo-code:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// route("/city-search", "./search-cities.ts")
|
|
45
|
+
export async function loader({ request }) {
|
|
46
|
+
const { searchParams } = new URL(request.url);
|
|
47
|
+
return searchCities(searchParams.get("q"));
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
export function CitySearchCombobox() {
|
|
53
|
+
const fetcher = useFetcher();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<fetcher.Form action="/city-search">
|
|
57
|
+
<Combobox aria-label="Cities">
|
|
58
|
+
<ComboboxInput
|
|
59
|
+
name="q"
|
|
60
|
+
onChange={(event) =>
|
|
61
|
+
// submit the form onChange to get the list of cities
|
|
62
|
+
fetcher.submit(event.target.form)
|
|
63
|
+
}
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
{fetcher.data ? (
|
|
67
|
+
<ComboboxPopover className="shadow-popup">
|
|
68
|
+
{fetcher.data.length > 0 ? (
|
|
69
|
+
<ComboboxList>
|
|
70
|
+
{fetcher.data.map((city) => (
|
|
71
|
+
<ComboboxOption
|
|
72
|
+
key={city.id}
|
|
73
|
+
value={city.name}
|
|
74
|
+
/>
|
|
75
|
+
))}
|
|
76
|
+
</ComboboxList>
|
|
77
|
+
) : (
|
|
78
|
+
<span>No results found</span>
|
|
79
|
+
)}
|
|
80
|
+
</ComboboxPopover>
|
|
81
|
+
) : null}
|
|
82
|
+
</Combobox>
|
|
83
|
+
</fetcher.Form>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Calls to `fetcher.submit` will cancel pending requests on that fetcher automatically. This ensures you never show the user results for a request for a different input value.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: React Transitions
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# React Transitions
|
|
6
|
+
|
|
7
|
+
[MODES: framework, data, declarative]
|
|
8
|
+
|
|
9
|
+
<br/>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
[React 18][react-18] introduced the concept of "transitions" which allow you to differentiate urgent from non-urgent UI updates. To learn more about React Transitions and "concurrent rendering" Please refer to React's official documentation:
|
|
13
|
+
|
|
14
|
+
- [What is Concurrent React][concurrent]
|
|
15
|
+
- [Transitions][transitions]
|
|
16
|
+
- [`React.useTransition`][use-transition]
|
|
17
|
+
- [`React.startTransition`][start-transition]
|
|
18
|
+
|
|
19
|
+
[React 19][react-19] enhances the async/concurrent landscape by introducing [Actions][actions] and support for using async functions in Transitions. With the support for async Transitions, a new [`React.useOptimistic`][use-optimistic-blog] [hook][use-optimistic] was also introduced that allows you to surface state updates during a Transition to show users instant feedback.
|
|
20
|
+
|
|
21
|
+
## Transitions in React Router
|
|
22
|
+
|
|
23
|
+
The introduction of Transitions in React makes the story of how React Router manages your navigations and router state a bit more complicated. These are powerful APIs but they don't come without some nuance and added complexity. We aim to make React Router work seamlessly with the new React features, but in some cases there may exist some tension between the new React ways to do things and some patterns you are already using in your React Router apps (i.e., pending states, optimistic UI).
|
|
24
|
+
|
|
25
|
+
To ensure a smooth adoption story, we've introduced changes related to Transitions behind an opt-in `useTransitions` flag so that you can upgrade in a non-breaking fashion.
|
|
26
|
+
|
|
27
|
+
### Current Behavior
|
|
28
|
+
|
|
29
|
+
We first leveraged `React.startTransition` to make React Router more Suspense-friendly in React Router [6.13.0][rr-6-13-0] via the `future.v7_startTransition` flag. In v7, that became the default behavior and all router state updates are currently wrapped in `React.startTransition`.
|
|
30
|
+
|
|
31
|
+
This default behavior has 2 potential issues that `useTransitions` is designed to solve:
|
|
32
|
+
|
|
33
|
+
- There are some valid use cases where you _don't_ want your updates wrapped in `startTransition`
|
|
34
|
+
- One specific issue is that `React.useSyncExternalStore` updates can't be Transitions ([^1][uses-transition-issue], [^2][uses-transition-tweet]). `useSyncExternalStore` forces a sync update, which means fallbacks can be shown in update transitions that would otherwise avoid showing the fallback.
|
|
35
|
+
- React Router has a `flushSync` option on navigations to use [`React.flushSync`][flush-sync] for state updates instead, but that's not always a proper solution
|
|
36
|
+
- React 19 has added a new `startTransition(() => Promise))` API as well as a new `useOptimistic` hook to surface updates during Transitions
|
|
37
|
+
- Without some updates to React Router, `startTransition(() => navigate(path))` doesn't work as you might expect, because we are not using `useOptimistic` internally so router state updates don't surface during the navigation, which breaks hooks like `useNavigation`
|
|
38
|
+
|
|
39
|
+
To provide a solution to both of the above issues, we're introducing a new `useTransitions` prop to the router components that will let you opt-out of using `startTransition` for router state updates (solving the first issue), or opt-into a more enhanced usage of `startTransition` + `useOptimistic` (solving the second issue). Because the current behavior is a bit incomplete with the new React 19 APIs, we plan to make the opt-in behavior the default in React Router v8, but we will likely retain the opt-out flag for use cases such as `useSyncExternalStore`.
|
|
40
|
+
|
|
41
|
+
### Opt-out via `useTransitions=false`
|
|
42
|
+
|
|
43
|
+
If your application is not "Transition-friendly" due to the usage of `useSyncExternalStore` (or other reasons), then you can opt-out via the prop:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
// Framework Mode (entry.client.tsx)
|
|
47
|
+
<HydratedRouter useTransitions={false} />
|
|
48
|
+
|
|
49
|
+
// Data Mode
|
|
50
|
+
<RouterProvider useTransitions={false} />
|
|
51
|
+
|
|
52
|
+
// Declarative Mode
|
|
53
|
+
<BrowserRouter useTransitions={false} />
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This will stop the router from wrapping internal state updates in `startTransition`.
|
|
57
|
+
|
|
58
|
+
### Opt-in via `useTransitions=true`
|
|
59
|
+
|
|
60
|
+
<docs-info>Opting into this feature in Framework or Data Mode requires that you are using React 19 because it needs access to [`React.useOptimistic`][use-optimistic]</docs-info>
|
|
61
|
+
|
|
62
|
+
If you want to make your application play nicely with all of the new React 19 features that rely on concurrent mode and Transitions, then you can opt-in via the new prop:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
// Framework Mode (entry.client.tsx)
|
|
66
|
+
<HydratedRouter useTransitions />
|
|
67
|
+
|
|
68
|
+
// Data Mode
|
|
69
|
+
<RouterProvider useTransitions />
|
|
70
|
+
|
|
71
|
+
// Declarative Mode
|
|
72
|
+
<BrowserRouter useTransitions />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With this flag enabled:
|
|
76
|
+
|
|
77
|
+
- All internal state updates are wrapped in `React.startTransition` (current behavior without the flag)
|
|
78
|
+
- All `<Link>`/`<Form>` navigations will be wrapped in `React.startTransition`, using the promise returned by `useNavigate`/`useSubmit` so that the Transition lasts for the duration of the navigation
|
|
79
|
+
- `useNavigate`/`useSubmit` do not automatically wrap in `React.startTransition`, so you can opt-out of a Transition-enabled navigation by using those directly
|
|
80
|
+
- In Framework/Data modes, a subset of the router state updates during a navigation will be surfaced to the UI via `useOptimistic`
|
|
81
|
+
- State related to the _ongoing_ navigation and all fetcher information will be surfaced:
|
|
82
|
+
- `state.navigation` for `useNavigation()`
|
|
83
|
+
- `state.revalidation` for `useRevalidator()`
|
|
84
|
+
- `state.actionData` for `useActionData()`
|
|
85
|
+
- `state.fetchers` for `useFetcher()` and `useFetchers()`
|
|
86
|
+
- State related to the _current_ location will not be surfaced:
|
|
87
|
+
- `state.location` for `useLocation`
|
|
88
|
+
- `state.matches` for `useMatches()`,
|
|
89
|
+
- `state.loaderData` for `useLoaderData()`
|
|
90
|
+
- `state.errors` for `useRouteError()`
|
|
91
|
+
- etc.
|
|
92
|
+
|
|
93
|
+
Enabling this flag means that you can now have fully-Transition-enabled navigations that play nicely with any other ongoing Transition-enabled aspects of your application.
|
|
94
|
+
|
|
95
|
+
The only APIs that are automatically wrapped in an async Transition are `<Link>` and `<Form>`. For everything else, you need to wrap the operation in `startTransition` yourself.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
// Automatically Transition-enabled
|
|
99
|
+
<Link to="/path" />
|
|
100
|
+
<Form method="post" action="/path" />
|
|
101
|
+
|
|
102
|
+
// Manually Transition-enabled
|
|
103
|
+
startTransition(() => navigate("/path"));
|
|
104
|
+
startTransition(() => submit(data, { method: 'post', action: "/path" }));
|
|
105
|
+
startTransition(() => fetcher.load("/path"));
|
|
106
|
+
startTransition(() => fetcher.submit(data, { method: "post", action: "/path" }));
|
|
107
|
+
|
|
108
|
+
// Not Transition-enabled
|
|
109
|
+
navigate("/path");
|
|
110
|
+
submit(data, { method: 'post', action: "/path" });
|
|
111
|
+
fetcher.load("/path");
|
|
112
|
+
fetcher.submit(data, { method: "post", action: "/path" });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Important:** You must always `return` or `await` the `navigate` promise inside `startTransition` so that the Transition encompasses the full duration of the navigation. If you forget to `return` or `await` the promise, the Transition will end prematurely and things won't work as expected.
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
// ✅ Returned promise
|
|
119
|
+
startTransition(() => navigate("/path"));
|
|
120
|
+
startTransition(() => {
|
|
121
|
+
setOptimistic(something);
|
|
122
|
+
return navigate("/path"));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ✅ Awaited promise
|
|
126
|
+
startTransition(async () => {
|
|
127
|
+
setOptimistic(something);
|
|
128
|
+
await navigate("/path"));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// ❌ Non-returned promise
|
|
132
|
+
startTransition(() => {
|
|
133
|
+
setOptimistic(something);
|
|
134
|
+
navigate("/path"));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ❌ Non-Awaited promise
|
|
138
|
+
startTransition(async () => {
|
|
139
|
+
setOptimistic(something);
|
|
140
|
+
navigate("/path"));
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### `popstate` navigations
|
|
145
|
+
|
|
146
|
+
There is currently a bug with optimistic states and `popstate`. If you need to read the current route during a back navigation, which cannot complete synchronously (e.g. Suspends on uncached data), you can set the optimistic state before navigating back or defer the optimistic update in a timer or microtask.
|
|
147
|
+
|
|
148
|
+
[react-18]: https://react.dev/blog/2022/03/29/react-v18
|
|
149
|
+
[concurrent]: https://react.dev/blog/2022/03/29/react-v18#what-is-concurrent-react
|
|
150
|
+
[transitions]: https://react.dev/blog/2022/03/29/react-v18#new-feature-transitions
|
|
151
|
+
[use-transition]: https://react.dev/reference/react/useTransition#reference
|
|
152
|
+
[start-transition]: https://react.dev/reference/react/startTransition
|
|
153
|
+
[react-19]: https://react.dev/blog/2024/12/05/react-19
|
|
154
|
+
[actions]: https://react.dev/blog/2024/12/05/react-19#actions
|
|
155
|
+
[use-optimistic-blog]: https://react.dev/blog/2024/12/05/react-19#new-hook-optimistic-updates
|
|
156
|
+
[use-optimistic]: https://react.dev/reference/react/useOptimistic
|
|
157
|
+
[flush-sync]: https://react.dev/reference/react-dom/flushSync
|
|
158
|
+
[rr-6-13-0]: https://github.com/remix-run/react-router/blob/main/CHANGELOG.md#v6130
|
|
159
|
+
[uses-transition-issue]: https://github.com/facebook/react/issues/26382
|
|
160
|
+
[uses-transition-tweet]: https://x.com/rickhanlonii/status/1683636856808775682
|