Skip to content

Commit f27fcf2

Browse files
authored
Fix a few edge case bugs with hybrid ssr:false/prerender scenarios (#13021)
1 parent 3e85155 commit f27fcf2

File tree

7 files changed

+754
-98
lines changed

7 files changed

+754
-98
lines changed

.changeset/nice-wombats-perform.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Properly handle revalidations to across a prerender/SPA boundary
6+
7+
- In "hybrid" applications where some routes are pre-rendered and some are served from a SPA fallback, we need to avoid making `.data` requests if the path wasn't pre-rendered because the request will 404
8+
- We don't know all the pre-rendered paths client-side, however:
9+
- All `loader` data in `ssr:false` mode is static because it's generated at build time
10+
- A route must use a `clientLoader` to do anything dynamic
11+
- Therefore, if a route only has a `loader` and not a `clientLoader`, we disable revalidation by default because there is no new data to retrieve
12+
- We short circuit and skip single fetch `.data` request logic if there are no server loaders with `shouldLoad=true` in our single fetch `dataStrategy`
13+
- This ensures that the route doesn't cause a `.data` request that would 404 after a submission

.changeset/nice-wombats-perform2.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Error at build time in `ssr:false` + `prerender` apps for the edge case scenario of:
6+
7+
- A parent route has only a `loader` (does not have a `clientLoader`)
8+
- The parent route is pre-rendered
9+
- The parent route has children routes which are not prerendered
10+
- This means that when the child paths are loaded via the SPA fallback, the parent won't have any `loaderData` because there is no server on which to run the `loader`
11+
- This can be resolved by either adding a parent `clientLoader` or pre-rendering the child paths
12+
- If you add a `clientLoader`, calling the `serverLoader()` on non-prerendered paths will throw a 404

0 commit comments

Comments
 (0)