Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove optimistic navigation behavior when prefetch is false (#58413)
### What? When navigating between pages (via `prefetch: false`) within a dynamic segment, the shared layout is re-rendered. This can cause unexpected behavior like layout data changing when navigating between child segments. ### Why? When prefetch is false, we're currently opting into an "optimistic navigation" codepath, which will optimistically render layout-routers up to the point where data is missing, while kicking off data fetches. It attempts to determine where refetching needs to happen by traversing the router cache nodes and checking where data is missing. However, it locates these cache nodes by using "segments" obtained by [deconstructing the URL](https://github.com/vercel/next.js/blob/fix/optimistic-bailout/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts#L142), which won't accurately contain dynamic segment data. For ex, `/en` which corresponds with `/app/[lang]/page.tsx` will have a cache node key of `lang|en|d`, not `en`. Similarly, the optimistic tree that gets constructed will also be incorrect, since it uses the URL segment. ### How? My initial fix was to match the dynamic segment against the segment constructed by the URL. But after discussion with @sebmarkbage and the team, it seems more correct to remove the optimistic case all together as there's no guarantee that the url will actually match to that segment. Fixes #50670 --------- Co-authored-by: Tim Neutkens <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information