-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support partial hydration for Remix clientLoader/clientAction (#11033)
- Loading branch information
1 parent
cb53f41
commit 0d2a38c
Showing
22 changed files
with
1,445 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
"@remix-run/router": minor | ||
--- | ||
|
||
Added a new `future.v7_partialHydration` future flag that enables partial hydration of a data router when Server-Side Rendering. This allows you to provide `hydrationData.loaderData` that has values for _some_ initially matched route loaders, but not all. When this flag is enabled, the router will call `loader` functions for routes that do not have hydration loader data during `router.initialize()`, and it will render down to the deepest provided `HydrateFallback` (up to the first route without hydration data) while it executes the unhydrated routes. | ||
|
||
For example, the following router has a `root` and `index` route, but only provided `hydrationData.loaderData` for the `root` route. Because the `index` route has a `loader`, we need to run that during initialization. With `future.v7_partialHydration` specified, `<RouterProvider>` will render the `RootComponent` (because it has data) and then the `IndexFallback` (since it does not have data). Once `indexLoader` finishes, application will update and display `IndexComponent`. | ||
|
||
```jsx | ||
let router = createBrowserRouter( | ||
[ | ||
{ | ||
id: "root", | ||
path: "/", | ||
loader: rootLoader, | ||
Component: RootComponent, | ||
Fallback: RootFallback, | ||
children: [ | ||
{ | ||
id: "index", | ||
index: true, | ||
loader: indexLoader, | ||
Component: IndexComponent, | ||
HydrateFallback: IndexFallback, | ||
}, | ||
], | ||
}, | ||
], | ||
{ | ||
future: { | ||
v7_partialHydration: true, | ||
}, | ||
hydrationData: { | ||
loaderData: { | ||
root: { message: "Hydrated from Root!" }, | ||
}, | ||
}, | ||
} | ||
); | ||
``` | ||
|
||
If the above example did not have an `IndexFallback`, then `RouterProvider` would instead render the `RootFallback` while it executed the `indexLoader`. | ||
|
||
**Note:** When `future.v7_partialHydration` is provided, the `<RouterProvider fallbackElement>` prop is ignored since you can move it to a `Fallback` on your top-most route. The `fallbackElement` prop will be removed in React Router v7 when `v7_partialHydration` behavior becomes the standard behavior. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: hydrateFallbackElement | ||
new: true | ||
--- | ||
|
||
# `hydrateFallbackElement` | ||
|
||
If you are using [Server-Side Rendering][ssr] and you are leveraging [partial hydration][partialhydration], then you can specify an Element/Component to render for non-hydrated routes during the initial hydration of the application. | ||
|
||
<docs-info>If you do not wish to specify a React element (i.e., `hydrateFallbackElement={<MyFallback />}`) you may specify an `HydrateFallback` component instead (i.e., `HydrateFallback={MyFallback}`) and React Router will call `createElement` for you internally.</docs-info> | ||
|
||
<docs-warning>This feature only works if using a data router, see [Picking a Router][pickingarouter]</docs-warning> | ||
|
||
```tsx | ||
let router = createBrowserRouter( | ||
[ | ||
{ | ||
id: "root", | ||
path: "/", | ||
loader: rootLoader, | ||
Component: Root, | ||
children: [ | ||
{ | ||
id: "invoice", | ||
path: "invoices/:id", | ||
loader: loadInvoice, | ||
Component: Invoice, | ||
HydrateFallback: InvoiceSkeleton, | ||
}, | ||
], | ||
}, | ||
], | ||
{ | ||
future: { | ||
v7_partialHydration: true, | ||
}, | ||
hydrationData: { | ||
root: { | ||
/*...*/ | ||
}, | ||
// No hydration data provided for the `invoice` route | ||
}, | ||
} | ||
); | ||
``` | ||
|
||
<docs-warning>There is no default fallback and it will just render `null` at that route level, so it is recommended that you always provide your own fallback element.</docs-warning> | ||
|
||
[pickingarouter]: ../routers/picking-a-router | ||
[ssr]: ../guides/ssr | ||
[partialhydration]: ../routers/create-browser-router#partial-hydration-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.