next.js
81ce3af8 - [Segment Cache] Hard nav when root layout changes (#76163)

Commit
1 year ago
[Segment Cache] Hard nav when root layout changes (#76163) The highest-level layout in a route tree is referred to as the "root" layout. When it changes, we perform a full-page (MPA-style) navigation. To implement this for the Segment Cache, I moved the `isNavigatingToNewRootLayout` check from `navigateReducer` into `startPPRNavigation`. Rather than run the `isNavigatingToNewRootLayout` check on every navigation, I combined it with the route tree traversal we already perform when diffing the tree on navigation. In the common case, navigation happens inside the root layout. If we discover a root layout before the first new segment is reached, we don't have to do anything extra. The only special case is when a root parameter changes. Although this triggers a re-render of that segment, it shouldn't cause the root layout to be treated as different for the purposes of deciding whether to trigger an MPA navigation. It's only in this case where we need to switch to a different tree traversal (isNavigatingToNewRootLayout).
Author
Parents
Loading