Commit 3fc6846
committed
Refresh on route tree mismatch
During a dynamic navigation, the server may respond with a different
route tree than the one we expected. This typically happens due to a
conditional server-side routing change.
This shouldn't happen under normal circumstances, but in some cases
it's unavoidable. Such as a user logging in/out from a different client.
When it does happen, Next.js must recover to a consistent state. This
may involve a brief flash of the incorrect route before the mismatch
is detected.
The recovery mechanism is simple enough: we refresh the page, using
whatever tree the server responds with (bypassing any older version
we may have cached locally). Also, because a route mismatch implies
some sort of server-side mutation, we also evict all the dynamic data
in the client's cache. Similar to what we do when a cookie is mutated
by a Server Action, or in response to a refresh() call.
This replaces the need for the lazy data fetch that happens in
LayoutRouter, via the server-patch reducer. I've left the existing
server-patch logic in place until I've finished migrating the reducers
over to the new implementation. In the meantime, I updated LayoutRouter
to disable the lazy data fetching branch for any navigation produced
by a reducer that has already been ported.1 parent 6cffd64 commit 3fc6846
File tree
19 files changed
+709
-179
lines changed- packages/next/src/client/components
- router-reducer
- reducers
- segment-cache
- test
- e2e/app-dir
- parallel-routes-and-interception-from-root
- segment-cache/metadata
- lib
19 files changed
+709
-179
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 82 | + | |
89 | 83 | | |
90 | 84 | | |
91 | 85 | | |
| |||
383 | 377 | | |
384 | 378 | | |
385 | 379 | | |
386 | | - | |
387 | 380 | | |
388 | 381 | | |
389 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
382 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
383 | 400 | | |
384 | 401 | | |
385 | 402 | | |
| |||
418 | 435 | | |
419 | 436 | | |
420 | 437 | | |
| 438 | + | |
421 | 439 | | |
422 | 440 | | |
423 | 441 | | |
| |||
0 commit comments