react-router 8.5.1 → 8.5.2
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 +29 -3
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +1 -1
- package/dist/development/index-react-server.d.ts +43 -37
- package/dist/development/index-react-server.js +64 -6
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/await.js +1 -1
- package/dist/development/lib/components.d.ts +42 -38
- package/dist/development/lib/components.js +25 -29
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +13 -4
- package/dist/development/lib/dom/lib.d.ts +2 -2
- package/dist/development/lib/dom/lib.js +11 -4
- package/dist/development/lib/dom/server.js +1 -1
- package/dist/development/lib/dom/ssr/components.js +1 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/development/lib/dom/ssr/fallback.js +1 -1
- package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/development/lib/dom/ssr/hydration.js +1 -1
- package/dist/development/lib/dom/ssr/invariant.js +1 -1
- package/dist/development/lib/dom/ssr/links.js +1 -1
- package/dist/development/lib/dom/ssr/markup.js +1 -1
- package/dist/development/lib/dom/ssr/route-discovery.js +1 -1
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/development/lib/dom/ssr/routes.js +1 -1
- package/dist/development/lib/dom/ssr/server.js +1 -1
- package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +4 -2
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.js +9 -4
- package/dist/development/lib/href.js +4 -4
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/development/lib/router/matcher.js +1 -1
- package/dist/development/lib/router/navigation.js +17 -2
- package/dist/development/lib/router/router.js +5 -2
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +6 -5
- package/dist/development/lib/router/utils.js +17 -8
- package/dist/development/lib/rsc/browser.js +26 -3
- package/dist/development/lib/rsc/errorBoundaries.js +1 -1
- package/dist/development/lib/rsc/html-stream/browser.js +1 -1
- package/dist/development/lib/rsc/html-stream/server.js +1 -1
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +2 -0
- package/dist/development/lib/rsc/server.ssr.js +1 -1
- package/dist/development/lib/server-runtime/cookies.js +1 -1
- package/dist/development/lib/server-runtime/crypto.js +1 -1
- package/dist/development/lib/server-runtime/data.js +1 -1
- package/dist/development/lib/server-runtime/dev.js +1 -1
- package/dist/development/lib/server-runtime/entry.js +1 -1
- package/dist/development/lib/server-runtime/errors.js +1 -1
- package/dist/development/lib/server-runtime/headers.js +1 -1
- package/dist/development/lib/server-runtime/invariant.js +1 -1
- package/dist/development/lib/server-runtime/mode.js +1 -1
- package/dist/development/lib/server-runtime/routeMatching.js +1 -1
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +9 -6
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.js +1 -1
- package/dist/development/lib/server-runtime/single-fetch.js +1 -1
- package/dist/development/lib/server-runtime/urls.js +1 -1
- package/dist/development/lib/server-runtime/warnings.js +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/route-module-annotations.d.ts +1 -1
- package/dist/development/route-pattern.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +75 -66
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
- package/dist/production/dom-export.js +1 -1
- package/dist/production/index-react-server-client.js +1 -1
- package/dist/production/index-react-server.d.ts +43 -37
- package/dist/production/index-react-server.js +64 -6
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/await.js +1 -1
- package/dist/production/lib/components.d.ts +42 -38
- package/dist/production/lib/components.js +25 -29
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +13 -4
- package/dist/production/lib/dom/lib.d.ts +2 -2
- package/dist/production/lib/dom/lib.js +11 -4
- package/dist/production/lib/dom/server.js +1 -1
- package/dist/production/lib/dom/ssr/components.js +1 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/production/lib/dom/ssr/fallback.js +1 -1
- package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/production/lib/dom/ssr/hydration.js +1 -1
- package/dist/production/lib/dom/ssr/invariant.js +1 -1
- package/dist/production/lib/dom/ssr/links.js +1 -1
- package/dist/production/lib/dom/ssr/markup.js +1 -1
- package/dist/production/lib/dom/ssr/route-discovery.js +1 -1
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/production/lib/dom/ssr/routes.js +1 -1
- package/dist/production/lib/dom/ssr/server.js +1 -1
- package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +4 -2
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.js +9 -4
- package/dist/production/lib/href.js +4 -4
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/production/lib/router/matcher.js +1 -1
- package/dist/production/lib/router/navigation.js +17 -2
- package/dist/production/lib/router/router.js +5 -2
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +6 -5
- package/dist/production/lib/router/utils.js +17 -8
- package/dist/production/lib/rsc/browser.js +26 -3
- package/dist/production/lib/rsc/errorBoundaries.js +1 -1
- package/dist/production/lib/rsc/html-stream/browser.js +1 -1
- package/dist/production/lib/rsc/html-stream/server.js +1 -1
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +2 -0
- package/dist/production/lib/rsc/server.ssr.js +1 -1
- package/dist/production/lib/server-runtime/cookies.js +1 -1
- package/dist/production/lib/server-runtime/crypto.js +1 -1
- package/dist/production/lib/server-runtime/data.js +1 -1
- package/dist/production/lib/server-runtime/dev.js +1 -1
- package/dist/production/lib/server-runtime/entry.js +1 -1
- package/dist/production/lib/server-runtime/errors.js +1 -1
- package/dist/production/lib/server-runtime/headers.js +1 -1
- package/dist/production/lib/server-runtime/invariant.js +1 -1
- package/dist/production/lib/server-runtime/mode.js +1 -1
- package/dist/production/lib/server-runtime/routeMatching.js +1 -1
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +9 -6
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.js +1 -1
- package/dist/production/lib/server-runtime/single-fetch.js +1 -1
- package/dist/production/lib/server-runtime/urls.js +1 -1
- package/dist/production/lib/server-runtime/warnings.js +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/route-module-annotations.d.ts +1 -1
- package/dist/production/route-pattern.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +75 -66
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/upgrading/v7.md +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
+
## v8.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Keep navigation metadata consistent after a submission action throws an error ([#15621](https://github.com/remix-run/react-router/pull/15621))
|
|
8
|
+
- Use the committed history action for loader `dataStrategy` navigation types and loading navigation history actions
|
|
9
|
+
- Cancel the discarded response body for `HEAD` requests, so a resource route streaming a file no longer leaks its file descriptor ([#15634](https://github.com/remix-run/react-router/pull/15634))
|
|
10
|
+
- Keep observing nested deferred promise rejections after cancelling a data response so they cannot crash the server
|
|
11
|
+
- Preserve streamed `<Suspense>` boundaries during hydration in development ([#15382](https://github.com/remix-run/react-router/pull/15382))
|
|
12
|
+
- Wrap the critical CSS reset in `React.startTransition` to prevent React 19 from silently discarding the server HTML and rendering the boundary on the client
|
|
13
|
+
- Fix submissions to root form actions containing search parameters or a hash when a `basename` is configured ([#15725](https://github.com/remix-run/react-router/pull/15725))
|
|
14
|
+
- Fix `href()` to throw for `null` required parameters and omit `null` splat parameters without a trailing slash, matching the behavior for `undefined` and the defined types ([#15754](https://github.com/remix-run/react-router/pull/15754))
|
|
15
|
+
- Fix generated `MetaArgs.matches` types to stop at the current route instead of appending an unknown, possibly undefined tail ([#15697](https://github.com/remix-run/react-router/pull/15697))
|
|
16
|
+
- Improve path generation and URL validation across `href()`, `generatePath()`, links, forms, fetchers, and redirects ([#15785](https://github.com/remix-run/react-router/pull/15785))
|
|
17
|
+
- Stop `redirect()`, `redirectDocument()` and `replace()` from setting `status: 302` on the `ResponseInit` passed to them ([#15753](https://github.com/remix-run/react-router/pull/15753))
|
|
18
|
+
- Later responses created from the same init object no longer get status 302, and a frozen init no longer throws
|
|
19
|
+
- Clear an `<Await>` render error when it receives a new `resolve` value, so the error element no longer stays on screen after navigating to a route whose data renders fine ([#15695](https://github.com/remix-run/react-router/pull/15695))
|
|
20
|
+
- Run `clientMiddleware` during RSC client navigations and preserve it when route components update via HMR ([#15763](https://github.com/remix-run/react-router/pull/15763))
|
|
21
|
+
- Handle `HEAD` resource responses consistently in RSC Framework and RSC Data modes ([#15783](https://github.com/remix-run/react-router/pull/15783))
|
|
22
|
+
- Fix initial rendering of RSC routes with a `clientLoader` and no `HydrateFallback` ([#15763](https://github.com/remix-run/react-router/pull/15763))
|
|
23
|
+
- Fix `<ScrollRestoration>` throwing an uncaught error before hydration when `sessionStorage` is unavailable ([#15566](https://github.com/remix-run/react-router/pull/15566))
|
|
24
|
+
- The inline restore script already logged the storage error, but its cleanup call accessed `sessionStorage` again and threw (e.g. Chrome with "Block all cookies", sandboxed cross-origin iframes)
|
|
25
|
+
- The error is still logged with `console.error`; only the second, uncaught throw is removed
|
|
26
|
+
- Fix `useBlocker` leaving behind a stale blocker that keeps blocking navigation after its component is hidden and shown again with `<Activity>`, or after the router is recreated ([#15710](https://github.com/remix-run/react-router/pull/15710))
|
|
27
|
+
|
|
3
28
|
## v8.5.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
6
31
|
|
|
7
|
-
- Fix `URIError: URI malformed` when an
|
|
32
|
+
- Fix `URIError: URI malformed` when an `ssr: false` dev server receives a URL path with a malformed percent-encoding ([#15649](https://github.com/remix-run/react-router/pull/15649))
|
|
8
33
|
- Bound server route manifest processing for paths with expensive route expansion ([#15703](https://github.com/remix-run/react-router/pull/15703))
|
|
9
34
|
- Fall back to initial route discovery during server rendering and RSC document/data requests
|
|
10
35
|
- Account for the number and depth of candidate branches when using regex matching
|
|
@@ -25,7 +50,6 @@
|
|
|
25
50
|
- Return fetchers to `idle` when a revalidation completes a pending navigation started by another fetcher's redirect
|
|
26
51
|
- Avoid adding an incompatible `document.startViewTransition()` overload to the global `Document` type ([#15680](https://github.com/remix-run/react-router/pull/15680))
|
|
27
52
|
- Allow transition results to be assigned to the DOM `ViewTransition` type
|
|
28
|
-
- Fix duplicate headers when throwing a redirect from an RSC server function ([#15667](https://github.com/remix-run/react-router/pull/15667))
|
|
29
53
|
- Skip `deleteData` in `destroySession` when the session has no ID ([#15639](https://github.com/remix-run/react-router/pull/15639))
|
|
30
54
|
- Avoid failures when destroying a session without a cookie on storage that rejects an empty key
|
|
31
55
|
- Surface the host's 404 response when a SPA fallback route has no prerendered data ([#15646](https://github.com/remix-run/react-router/pull/15646))
|
|
@@ -35,13 +59,15 @@
|
|
|
35
59
|
|
|
36
60
|
### Unstable Changes
|
|
37
61
|
|
|
38
|
-
⚠️
|
|
62
|
+
⚠️ _[Unstable features](https://reactrouter.com/community/api-development-strategy#unstable-flags) are not recommended for production use_
|
|
39
63
|
|
|
40
64
|
- Add an opt-in `<Await unstable_promise={promise}>` implementation based on React's `use()` API ([#15678](https://github.com/remix-run/react-router/pull/15678))
|
|
41
65
|
- Use `React.use` instead of React Router's internal promise tracking
|
|
42
66
|
- Accept promise-like values and retain `errorElement`, `useAsyncValue`, and `useAsyncError` support
|
|
43
67
|
- Handle only promise rejections with `errorElement` when using `unstable_promise`, allowing child render errors to bubble to the nearest React error boundary
|
|
44
68
|
- Track streamed promises during decoding so settled server content stays visible during hydration updates with either Await API or direct `React.use()`
|
|
69
|
+
- Fix `URIError: URI malformed` when an API-only (`ssr: "unstable_api-only"`) server receives a URL path with a malformed percent-encoding ([#15649](https://github.com/remix-run/react-router/pull/15649))
|
|
70
|
+
- Fix duplicate headers when throwing a redirect from an RSC server function ([#15667](https://github.com/remix-run/react-router/pull/15667))
|
|
45
71
|
|
|
46
72
|
## v8.5.0
|
|
47
73
|
|
|
@@ -679,7 +679,7 @@ type BaseRouteObject = {
|
|
|
679
679
|
action?: ActionFunction | boolean;
|
|
680
680
|
/**
|
|
681
681
|
* The route shouldRevalidate function.
|
|
682
|
-
* See [`shouldRevalidate`](../../start/data/route-object#
|
|
682
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
|
|
683
683
|
*/
|
|
684
684
|
shouldRevalidate?: ShouldRevalidateFunction;
|
|
685
685
|
/**
|
|
@@ -1014,7 +1014,25 @@ interface AwaitResolveRenderFunction<Resolve = any> {
|
|
|
1014
1014
|
* @category Types
|
|
1015
1015
|
*/
|
|
1016
1016
|
interface AwaitProps<Resolve> {
|
|
1017
|
-
/**
|
|
1017
|
+
/**
|
|
1018
|
+
* <docs-warning>This prop is currently unstable and may change in minor or patch
|
|
1019
|
+
* releases.</docs-warning>
|
|
1020
|
+
*
|
|
1021
|
+
* A promise (or value) to read using React's `use()` API in client components.
|
|
1022
|
+
* Unlike `resolve` in client components, this accepts promise-like values
|
|
1023
|
+
* without modifying the source promise.
|
|
1024
|
+
*
|
|
1025
|
+
* `errorElement` handles promise rejections. Errors thrown while rendering
|
|
1026
|
+
* children bubble to the nearest React error boundary.
|
|
1027
|
+
*
|
|
1028
|
+
* ```tsx
|
|
1029
|
+
* <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
|
|
1030
|
+
* {(reviews) => <Reviews items={reviews} />}
|
|
1031
|
+
* </Await>
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* Pass exactly one of `unstable_promise` or `resolve`.
|
|
1035
|
+
*/
|
|
1018
1036
|
unstable_promise?: never;
|
|
1019
1037
|
/**
|
|
1020
1038
|
* When using a function, the resolved value is provided as the parameter.
|
|
@@ -1041,14 +1059,17 @@ interface AwaitProps<Resolve> {
|
|
|
1041
1059
|
*/
|
|
1042
1060
|
children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
|
|
1043
1061
|
/**
|
|
1044
|
-
* The error element renders instead of the `children` when the
|
|
1062
|
+
* The error element renders instead of the `children` when the
|
|
1063
|
+
* [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
1045
1064
|
* rejects.
|
|
1046
1065
|
*
|
|
1066
|
+
* When using `resolve`, errors thrown while rendering `children` are
|
|
1067
|
+
* also caught and rendered here. With `unstable_promise`, only promise
|
|
1068
|
+
* rejections are handled; errors thrown while rendering `children` bubble to
|
|
1069
|
+
* the nearest React error boundary.
|
|
1070
|
+
*
|
|
1047
1071
|
* ```tsx
|
|
1048
|
-
* <Await
|
|
1049
|
-
* errorElement={<div>Oops</div>}
|
|
1050
|
-
* resolve={reviewsPromise}
|
|
1051
|
-
* >
|
|
1072
|
+
* <Await resolve={reviewsPromise} errorElement={<div>Oops</div>}>
|
|
1052
1073
|
* <Reviews />
|
|
1053
1074
|
* </Await>
|
|
1054
1075
|
* ```
|
|
@@ -1057,10 +1078,7 @@ interface AwaitProps<Resolve> {
|
|
|
1057
1078
|
* child component
|
|
1058
1079
|
*
|
|
1059
1080
|
* ```tsx
|
|
1060
|
-
* <Await
|
|
1061
|
-
* errorElement={<ReviewsError />}
|
|
1062
|
-
* resolve={reviewsPromise}
|
|
1063
|
-
* >
|
|
1081
|
+
* <Await resolve={reviewsPromise} errorElement={<ReviewsError />}>
|
|
1064
1082
|
* <Reviews />
|
|
1065
1083
|
* </Await>
|
|
1066
1084
|
*
|
|
@@ -1140,22 +1158,16 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
1140
1158
|
/**
|
|
1141
1159
|
* Used to render promise values with automatic error handling.
|
|
1142
1160
|
*
|
|
1143
|
-
*
|
|
1161
|
+
* Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
|
|
1162
|
+
* it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
|
|
1163
|
+
* API.
|
|
1144
1164
|
*
|
|
1145
|
-
*
|
|
1146
|
-
* [`use()`](https://react.dev/reference/react/use) implementation. With
|
|
1147
|
-
* `unstable_promise`, `errorElement` handles promise rejections, while errors
|
|
1148
|
-
* thrown by children bubble to the nearest React error boundary.
|
|
1149
|
-
*
|
|
1150
|
-
* In React Server Components, `resolve` already has this error-handling behavior:
|
|
1151
|
-
* `errorElement` handles only input rejections, while child render errors
|
|
1152
|
-
* propagate to the surrounding error boundary. Both props accept promise-like
|
|
1153
|
-
* values without modifying the source promise. Both props treat a falsy
|
|
1154
|
-
* `errorElement` as absent and propagate the rejection. Pass an empty fragment
|
|
1155
|
-
* to handle a rejection without rendering any content.
|
|
1165
|
+
* **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
|
|
1156
1166
|
*
|
|
1157
|
-
* <docs-warning>The `unstable_promise` prop is
|
|
1158
|
-
*
|
|
1167
|
+
* <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
|
|
1168
|
+
* releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
|
|
1169
|
+
* drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
|
|
1170
|
+
* between the two approaches.</docs-warning>
|
|
1159
1171
|
*
|
|
1160
1172
|
* @example
|
|
1161
1173
|
* import { Await, useLoaderData } from "react-router";
|
|
@@ -1175,15 +1187,9 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
1175
1187
|
* <h1>{book.title}</h1>
|
|
1176
1188
|
* <p>{book.description}</p>
|
|
1177
1189
|
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
1178
|
-
* <Await
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
* <div>Could not load reviews 😬</div>
|
|
1182
|
-
* }
|
|
1183
|
-
* children={(resolvedReviews) => (
|
|
1184
|
-
* <Reviews items={resolvedReviews} />
|
|
1185
|
-
* )}
|
|
1186
|
-
* />
|
|
1190
|
+
* <Await resolve={reviews} errorElement={<BookError />}>
|
|
1191
|
+
* {(resolvedReviews) => <Reviews items={resolvedReviews} />}
|
|
1192
|
+
* </Await>
|
|
1187
1193
|
* </React.Suspense>
|
|
1188
1194
|
* </div>
|
|
1189
1195
|
* );
|
|
@@ -1197,9 +1203,7 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
1197
1203
|
* @param {AwaitProps.children} props.children n/a
|
|
1198
1204
|
* @param {AwaitProps.errorElement} props.errorElement n/a
|
|
1199
1205
|
* @param {AwaitProps.resolve} props.resolve n/a
|
|
1200
|
-
* @param props.unstable_promise
|
|
1201
|
-
* API in client components. Accepts promise-like values without modifying the
|
|
1202
|
-
* source promise. Pass exactly one of `unstable_promise` or `resolve`.
|
|
1206
|
+
* @param {AwaitProps.unstable_promise} props.unstable_promise n/a
|
|
1203
1207
|
* @returns React element for the rendered awaited value
|
|
1204
1208
|
*/
|
|
1205
1209
|
declare function Await$1<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React.JSX.Element;
|
|
@@ -2330,6 +2334,7 @@ type RSCRouteConfigEntryBase = {
|
|
|
2330
2334
|
action?: ActionFunction;
|
|
2331
2335
|
clientAction?: ClientActionFunction;
|
|
2332
2336
|
clientLoader?: ClientLoaderFunction;
|
|
2337
|
+
clientMiddleware?: MiddlewareFunction<any>[];
|
|
2333
2338
|
ErrorBoundary?: React.ComponentType<any>;
|
|
2334
2339
|
handle?: any;
|
|
2335
2340
|
headers?: HeadersFunction;
|
|
@@ -2361,6 +2366,7 @@ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
|
|
|
2361
2366
|
type RSCRouteManifest = {
|
|
2362
2367
|
clientAction?: ClientActionFunction;
|
|
2363
2368
|
clientLoader?: ClientLoaderFunction;
|
|
2369
|
+
clientMiddleware?: MiddlewareFunction<any>[];
|
|
2364
2370
|
element?: React.ReactElement | false;
|
|
2365
2371
|
errorElement?: React.ReactElement;
|
|
2366
2372
|
handle?: any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -83,6 +83,46 @@ function parsePath(path) {
|
|
|
83
83
|
return parsedPath;
|
|
84
84
|
}
|
|
85
85
|
//#endregion
|
|
86
|
+
//#region lib/router/navigation.ts
|
|
87
|
+
const DEFAULT_NAVIGATION_URL = new URL("http://localhost");
|
|
88
|
+
function isSameOrigin(a, b) {
|
|
89
|
+
return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
|
|
90
|
+
}
|
|
91
|
+
function isExplicitUrl(destination, target) {
|
|
92
|
+
if (destination.startsWith("//")) return true;
|
|
93
|
+
let protocol = target.protocol.toLowerCase();
|
|
94
|
+
if (!destination.toLowerCase().startsWith(protocol)) return false;
|
|
95
|
+
return target.host === "" || destination.slice(protocol.length).startsWith("//");
|
|
96
|
+
}
|
|
97
|
+
function validateDocumentNavigationTarget(destination) {
|
|
98
|
+
let normalized = destination.replace(/[\t\n\r]/g, "");
|
|
99
|
+
let start = 0;
|
|
100
|
+
while (normalized.charCodeAt(start) <= 32) start++;
|
|
101
|
+
normalized = normalized.slice(start);
|
|
102
|
+
if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
|
|
103
|
+
let target;
|
|
104
|
+
try {
|
|
105
|
+
target = new URL(destination, DEFAULT_NAVIGATION_URL);
|
|
106
|
+
} catch {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!isExplicitUrl(destination, target)) throw new Error("External navigation is not allowed");
|
|
110
|
+
}
|
|
111
|
+
function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
|
|
112
|
+
let originalUrl = null;
|
|
113
|
+
try {
|
|
114
|
+
originalUrl = original == null ? null : new URL(original, currentUrl);
|
|
115
|
+
} catch {}
|
|
116
|
+
let resolvedUrl = new URL(resolved, currentUrl);
|
|
117
|
+
let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
|
|
118
|
+
let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
|
|
119
|
+
if (externalPolicy === "reject") {
|
|
120
|
+
if (originalIsExternal || resolvedIsExternal) throw new Error("External navigation is not allowed");
|
|
121
|
+
} else if (resolvedIsExternal) {
|
|
122
|
+
if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) throw new Error("External navigation is not allowed");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
86
126
|
//#region lib/router/utils.ts
|
|
87
127
|
/**
|
|
88
128
|
* Creates a type-safe {@link RouterContext} object that can be used to
|
|
@@ -730,11 +770,15 @@ function data(data, init) {
|
|
|
730
770
|
* header.
|
|
731
771
|
*/
|
|
732
772
|
const redirect$1 = (url, init = 302) => {
|
|
773
|
+
validateDocumentNavigationTarget(url);
|
|
733
774
|
let responseInit = init;
|
|
734
775
|
if (typeof responseInit === "number") responseInit = { status: responseInit };
|
|
735
|
-
else if (typeof responseInit.status === "undefined") responseInit.status = 302;
|
|
736
776
|
let headers = new Headers(responseInit.headers);
|
|
737
777
|
headers.set("Location", url);
|
|
778
|
+
if (typeof responseInit.status === "undefined") responseInit = {
|
|
779
|
+
...responseInit,
|
|
780
|
+
status: 302
|
|
781
|
+
};
|
|
738
782
|
return new Response(null, {
|
|
739
783
|
...responseInit,
|
|
740
784
|
headers
|
|
@@ -2018,6 +2062,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
|
|
2018
2062
|
function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
|
|
2019
2063
|
let location = response.headers.get("Location");
|
|
2020
2064
|
invariant$1(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
2065
|
+
validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
|
|
2021
2066
|
if (!isAbsoluteUrl(location)) {
|
|
2022
2067
|
let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
|
|
2023
2068
|
location = normalizeTo(new URL(request.url), trimmedMatches, basename, location);
|
|
@@ -2500,9 +2545,20 @@ async function matchRSCServerRequest({ allowedActionOrigins, createTemporaryRefe
|
|
|
2500
2545
|
let matches = staticHandler.match(url.pathname);
|
|
2501
2546
|
if (matches) await Promise.all(matches.map((m) => explodeLazyRoute(m.route)));
|
|
2502
2547
|
const leafMatch = matches?.[matches.length - 1];
|
|
2503
|
-
if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return generateResourceResponse(routerRequest, staticHandler, leafMatch.route.id, requestContext, onError);
|
|
2548
|
+
if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return normalizeResourceResponse(request, await generateResourceResponse(routerRequest, staticHandler, leafMatch.route.id, requestContext, onError));
|
|
2504
2549
|
let response = await generateRenderResponse(routerRequest, staticHandler, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences, allowedActionOrigins, routeDiscovery, clientVersion);
|
|
2505
2550
|
response.headers.set("X-Remix-Response", "yes");
|
|
2551
|
+
return normalizeResourceResponse(request, response);
|
|
2552
|
+
}
|
|
2553
|
+
function normalizeResourceResponse(request, response) {
|
|
2554
|
+
if (request.method === "HEAD" && response.headers.get("React-Router-Resource") === "true") {
|
|
2555
|
+
response.body?.cancel().catch(() => {});
|
|
2556
|
+
return new Response(null, {
|
|
2557
|
+
status: response.status,
|
|
2558
|
+
statusText: response.statusText,
|
|
2559
|
+
headers: response.headers
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2506
2562
|
return response;
|
|
2507
2563
|
}
|
|
2508
2564
|
async function generateManifestResponse(routes, basename, request, generateResponse, temporaryReferences, routeDiscovery, clientVersion) {
|
|
@@ -2860,6 +2916,7 @@ async function getRSCRouteMatch({ staticContext, match, isBelowErrorBoundary, ro
|
|
|
2860
2916
|
return {
|
|
2861
2917
|
clientAction: route.clientAction,
|
|
2862
2918
|
clientLoader: route.clientLoader,
|
|
2919
|
+
clientMiddleware: route.clientMiddleware,
|
|
2863
2920
|
element,
|
|
2864
2921
|
errorElement,
|
|
2865
2922
|
handle: route.handle,
|
|
@@ -2887,6 +2944,7 @@ async function getManifestRoute(route) {
|
|
|
2887
2944
|
return {
|
|
2888
2945
|
clientAction: route.clientAction,
|
|
2889
2946
|
clientLoader: route.clientLoader,
|
|
2947
|
+
clientMiddleware: route.clientMiddleware,
|
|
2890
2948
|
handle: route.handle,
|
|
2891
2949
|
hasAction: !!route.action,
|
|
2892
2950
|
hasComponent: !!route.Component,
|
|
@@ -2996,14 +3054,14 @@ function href(path, ...args) {
|
|
|
2996
3054
|
let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
|
|
2997
3055
|
const isRequired = questionMark === void 0;
|
|
2998
3056
|
const value = params?.[param];
|
|
2999
|
-
if (isRequired && value
|
|
3057
|
+
if (isRequired && value == null) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
|
|
3000
3058
|
return value == null ? "" : "/" + encodePathParam(stringify(value));
|
|
3001
3059
|
});
|
|
3002
3060
|
if (path.endsWith("*")) {
|
|
3003
3061
|
const value = params?.["*"];
|
|
3004
|
-
if (value
|
|
3062
|
+
if (value != null) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
|
|
3005
3063
|
}
|
|
3006
|
-
return result || "/";
|
|
3064
|
+
return result.replace(/^\/{2,}/, "/") || "/";
|
|
3007
3065
|
}
|
|
3008
3066
|
/**
|
|
3009
3067
|
* Removes a trailing splat and any number of slashes from the end of the path.
|
|
@@ -447,7 +447,7 @@ interface PathRouteProps {
|
|
|
447
447
|
action?: NonIndexRouteObject["action"];
|
|
448
448
|
/**
|
|
449
449
|
* The route shouldRevalidate function.
|
|
450
|
-
* See [`shouldRevalidate`](../../start/data/route-object#
|
|
450
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
|
|
451
451
|
*/
|
|
452
452
|
shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
|
|
453
453
|
/**
|
|
@@ -537,7 +537,7 @@ interface IndexRouteProps {
|
|
|
537
537
|
action?: IndexRouteObject["action"];
|
|
538
538
|
/**
|
|
539
539
|
* The route shouldRevalidate function.
|
|
540
|
-
* See [`shouldRevalidate`](../../start/data/route-object#
|
|
540
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
|
|
541
541
|
*/
|
|
542
542
|
shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
|
|
543
543
|
/**
|
|
@@ -768,7 +768,25 @@ interface AwaitResolveRenderFunction<Resolve = any> {
|
|
|
768
768
|
* @category Types
|
|
769
769
|
*/
|
|
770
770
|
interface AwaitProps<Resolve> {
|
|
771
|
-
/**
|
|
771
|
+
/**
|
|
772
|
+
* <docs-warning>This prop is currently unstable and may change in minor or patch
|
|
773
|
+
* releases.</docs-warning>
|
|
774
|
+
*
|
|
775
|
+
* A promise (or value) to read using React's `use()` API in client components.
|
|
776
|
+
* Unlike `resolve` in client components, this accepts promise-like values
|
|
777
|
+
* without modifying the source promise.
|
|
778
|
+
*
|
|
779
|
+
* `errorElement` handles promise rejections. Errors thrown while rendering
|
|
780
|
+
* children bubble to the nearest React error boundary.
|
|
781
|
+
*
|
|
782
|
+
* ```tsx
|
|
783
|
+
* <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
|
|
784
|
+
* {(reviews) => <Reviews items={reviews} />}
|
|
785
|
+
* </Await>
|
|
786
|
+
* ```
|
|
787
|
+
*
|
|
788
|
+
* Pass exactly one of `unstable_promise` or `resolve`.
|
|
789
|
+
*/
|
|
772
790
|
unstable_promise?: never;
|
|
773
791
|
/**
|
|
774
792
|
* When using a function, the resolved value is provided as the parameter.
|
|
@@ -795,14 +813,17 @@ interface AwaitProps<Resolve> {
|
|
|
795
813
|
*/
|
|
796
814
|
children: React$1.ReactNode | AwaitResolveRenderFunction<Resolve>;
|
|
797
815
|
/**
|
|
798
|
-
* The error element renders instead of the `children` when the
|
|
816
|
+
* The error element renders instead of the `children` when the
|
|
817
|
+
* [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
799
818
|
* rejects.
|
|
800
819
|
*
|
|
820
|
+
* When using `resolve`, errors thrown while rendering `children` are
|
|
821
|
+
* also caught and rendered here. With `unstable_promise`, only promise
|
|
822
|
+
* rejections are handled; errors thrown while rendering `children` bubble to
|
|
823
|
+
* the nearest React error boundary.
|
|
824
|
+
*
|
|
801
825
|
* ```tsx
|
|
802
|
-
* <Await
|
|
803
|
-
* errorElement={<div>Oops</div>}
|
|
804
|
-
* resolve={reviewsPromise}
|
|
805
|
-
* >
|
|
826
|
+
* <Await resolve={reviewsPromise} errorElement={<div>Oops</div>}>
|
|
806
827
|
* <Reviews />
|
|
807
828
|
* </Await>
|
|
808
829
|
* ```
|
|
@@ -811,10 +832,7 @@ interface AwaitProps<Resolve> {
|
|
|
811
832
|
* child component
|
|
812
833
|
*
|
|
813
834
|
* ```tsx
|
|
814
|
-
* <Await
|
|
815
|
-
* errorElement={<ReviewsError />}
|
|
816
|
-
* resolve={reviewsPromise}
|
|
817
|
-
* >
|
|
835
|
+
* <Await resolve={reviewsPromise} errorElement={<ReviewsError />}>
|
|
818
836
|
* <Reviews />
|
|
819
837
|
* </Await>
|
|
820
838
|
*
|
|
@@ -894,22 +912,16 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
894
912
|
/**
|
|
895
913
|
* Used to render promise values with automatic error handling.
|
|
896
914
|
*
|
|
897
|
-
*
|
|
915
|
+
* Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
|
|
916
|
+
* it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
|
|
917
|
+
* API.
|
|
898
918
|
*
|
|
899
|
-
*
|
|
900
|
-
* [`use()`](https://react.dev/reference/react/use) implementation. With
|
|
901
|
-
* `unstable_promise`, `errorElement` handles promise rejections, while errors
|
|
902
|
-
* thrown by children bubble to the nearest React error boundary.
|
|
903
|
-
*
|
|
904
|
-
* In React Server Components, `resolve` already has this error-handling behavior:
|
|
905
|
-
* `errorElement` handles only input rejections, while child render errors
|
|
906
|
-
* propagate to the surrounding error boundary. Both props accept promise-like
|
|
907
|
-
* values without modifying the source promise. Both props treat a falsy
|
|
908
|
-
* `errorElement` as absent and propagate the rejection. Pass an empty fragment
|
|
909
|
-
* to handle a rejection without rendering any content.
|
|
919
|
+
* **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
|
|
910
920
|
*
|
|
911
|
-
* <docs-warning>The `unstable_promise` prop is
|
|
912
|
-
*
|
|
921
|
+
* <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
|
|
922
|
+
* releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
|
|
923
|
+
* drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
|
|
924
|
+
* between the two approaches.</docs-warning>
|
|
913
925
|
*
|
|
914
926
|
* @example
|
|
915
927
|
* import { Await, useLoaderData } from "react-router";
|
|
@@ -929,15 +941,9 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
929
941
|
* <h1>{book.title}</h1>
|
|
930
942
|
* <p>{book.description}</p>
|
|
931
943
|
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
932
|
-
* <Await
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* <div>Could not load reviews 😬</div>
|
|
936
|
-
* }
|
|
937
|
-
* children={(resolvedReviews) => (
|
|
938
|
-
* <Reviews items={resolvedReviews} />
|
|
939
|
-
* )}
|
|
940
|
-
* />
|
|
944
|
+
* <Await resolve={reviews} errorElement={<BookError />}>
|
|
945
|
+
* {(resolvedReviews) => <Reviews items={resolvedReviews} />}
|
|
946
|
+
* </Await>
|
|
941
947
|
* </React.Suspense>
|
|
942
948
|
* </div>
|
|
943
949
|
* );
|
|
@@ -951,9 +957,7 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
|
|
|
951
957
|
* @param {AwaitProps.children} props.children n/a
|
|
952
958
|
* @param {AwaitProps.errorElement} props.errorElement n/a
|
|
953
959
|
* @param {AwaitProps.resolve} props.resolve n/a
|
|
954
|
-
* @param props.unstable_promise
|
|
955
|
-
* API in client components. Accepts promise-like values without modifying the
|
|
956
|
-
* source promise. Pass exactly one of `unstable_promise` or `resolve`.
|
|
960
|
+
* @param {AwaitProps.unstable_promise} props.unstable_promise n/a
|
|
957
961
|
* @returns React element for the rendered awaited value
|
|
958
962
|
*/
|
|
959
963
|
declare function Await<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React$1.JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { createMemoryHistory, createPath, invariant, parsePath, warning } from "./router/history.js";
|
|
12
|
-
import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
|
|
13
12
|
import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
|
|
13
|
+
import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
|
|
14
14
|
import { clientErrors, createRouter } from "./router/router.js";
|
|
15
15
|
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, LocationContext, NavigationContext, RouteContext, ViewTransitionContext, useIsRSCRouterContext } from "./context.js";
|
|
16
16
|
import { getAwaitPromise, getPromiseResult } from "./await.js";
|
|
@@ -649,22 +649,16 @@ function Routes({ children, location }) {
|
|
|
649
649
|
/**
|
|
650
650
|
* Used to render promise values with automatic error handling.
|
|
651
651
|
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
* [`use()`](https://react.dev/reference/react/use) implementation. With
|
|
656
|
-
* `unstable_promise`, `errorElement` handles promise rejections, while errors
|
|
657
|
-
* thrown by children bubble to the nearest React error boundary.
|
|
652
|
+
* Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
|
|
653
|
+
* it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
|
|
654
|
+
* API.
|
|
658
655
|
*
|
|
659
|
-
*
|
|
660
|
-
* `errorElement` handles only input rejections, while child render errors
|
|
661
|
-
* propagate to the surrounding error boundary. Both props accept promise-like
|
|
662
|
-
* values without modifying the source promise. Both props treat a falsy
|
|
663
|
-
* `errorElement` as absent and propagate the rejection. Pass an empty fragment
|
|
664
|
-
* to handle a rejection without rendering any content.
|
|
656
|
+
* **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
|
|
665
657
|
*
|
|
666
|
-
* <docs-warning>The `unstable_promise` prop is
|
|
667
|
-
*
|
|
658
|
+
* <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
|
|
659
|
+
* releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
|
|
660
|
+
* drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
|
|
661
|
+
* between the two approaches.</docs-warning>
|
|
668
662
|
*
|
|
669
663
|
* @example
|
|
670
664
|
* import { Await, useLoaderData } from "react-router";
|
|
@@ -684,15 +678,9 @@ function Routes({ children, location }) {
|
|
|
684
678
|
* <h1>{book.title}</h1>
|
|
685
679
|
* <p>{book.description}</p>
|
|
686
680
|
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
687
|
-
* <Await
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
* <div>Could not load reviews 😬</div>
|
|
691
|
-
* }
|
|
692
|
-
* children={(resolvedReviews) => (
|
|
693
|
-
* <Reviews items={resolvedReviews} />
|
|
694
|
-
* )}
|
|
695
|
-
* />
|
|
681
|
+
* <Await resolve={reviews} errorElement={<BookError />}>
|
|
682
|
+
* {(resolvedReviews) => <Reviews items={resolvedReviews} />}
|
|
683
|
+
* </Await>
|
|
696
684
|
* </React.Suspense>
|
|
697
685
|
* </div>
|
|
698
686
|
* );
|
|
@@ -706,9 +694,7 @@ function Routes({ children, location }) {
|
|
|
706
694
|
* @param {AwaitProps.children} props.children n/a
|
|
707
695
|
* @param {AwaitProps.errorElement} props.errorElement n/a
|
|
708
696
|
* @param {AwaitProps.resolve} props.resolve n/a
|
|
709
|
-
* @param props.unstable_promise
|
|
710
|
-
* API in client components. Accepts promise-like values without modifying the
|
|
711
|
-
* source promise. Pass exactly one of `unstable_promise` or `resolve`.
|
|
697
|
+
* @param {AwaitProps.unstable_promise} props.unstable_promise n/a
|
|
712
698
|
* @returns React element for the rendered awaited value
|
|
713
699
|
*/
|
|
714
700
|
function Await(props) {
|
|
@@ -746,11 +732,21 @@ function AwaitPromise({ value, children, errorElement, onError }) {
|
|
|
746
732
|
var AwaitErrorBoundary = class extends React$1.Component {
|
|
747
733
|
constructor(props) {
|
|
748
734
|
super(props);
|
|
749
|
-
this.state = {
|
|
735
|
+
this.state = {
|
|
736
|
+
error: null,
|
|
737
|
+
resolve: props.resolve
|
|
738
|
+
};
|
|
750
739
|
}
|
|
751
740
|
static getDerivedStateFromError(error) {
|
|
752
741
|
return { error };
|
|
753
742
|
}
|
|
743
|
+
static getDerivedStateFromProps(props, state) {
|
|
744
|
+
if (props.resolve !== state.resolve) return {
|
|
745
|
+
error: null,
|
|
746
|
+
resolve: props.resolve
|
|
747
|
+
};
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
754
750
|
componentDidCatch(error, errorInfo) {
|
|
755
751
|
if (this.props.onError) this.props.onError(error, errorInfo);
|
|
756
752
|
else console.error("<Await> caught the following error during render", error, errorInfo);
|