Skip to content

Commit 701a328

Browse files
committed
Handle redirects from hydrating clientLoaders
1 parent d1aaa2d commit 701a328

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/smooth-donuts-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Handle redirects from `clientLoader.hydrate` initial load executions

packages/react-router/lib/dom/ssr/single-fetch.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,19 @@ async function singleFetchLoaderNavigationStrategy(
428428
await Promise.all(routeDfds.map((d) => d.promise));
429429

430430
// We can skip the server call:
431-
// - On initial hydration - only clientLoaders can pass through via `clientLoader.hydrate`
431+
// - On initial hydration - only clientLoaders can pass through via
432+
// `clientLoader.hydrate`. We check the navigation state below as well
433+
// because if a clientLoader redirected we'll still be `initialized=false`
434+
// but we want to call loaders for the new location
432435
// - If there are no routes to fetch from the server
433436
//
434437
// One exception - if we are performing an HDR revalidation we have to call
435438
// the server in case a new loader has shown up that the manifest doesn't yet
436439
// know about
440+
let isInitialLoad =
441+
!router.state.initialized && router.state.navigation.state === "idle";
437442
if (
438-
(!router.state.initialized || routesParams.size === 0) &&
443+
(isInitialLoad || routesParams.size === 0) &&
439444
!window.__reactRouterHdrActive
440445
) {
441446
singleFetchDfd.resolve({ routes: {} });

0 commit comments

Comments
 (0)