mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
When navigating to a route that wasn't previously prefetched (e.g. via a
Link with prefetch={false}, or router.push()), the client stores the
route data from the server response in the cache so it can be reused by
future navigations and prefetches to the same URL.
These entries were being stored with a null "nextUrl" cache key, but
lookups use the real nextUrl from router state, so every subsequent
lookup missed. This caused redundant requests for route data the client
already had.
The fix threads the nextUrl through the route discovery path so it
reaches the cache write with the correct value. For non-intercepted
routes the entry is keyed with a wildcard (reusable regardless of
nextUrl); for intercepted routes it uses the specific nextUrl, since the
route structure varies by referrer.
Also cleans up how interception routes interact with the optimistic
route matching system: patterns are now always stored during discovery
(previously they were skipped), and the interception bailout happens in
a single place during matching rather than being duplicated across
multiple check sites.
Closes #88863
Co-authored-by: Hendrik Liebau <[email protected]>
Co-authored-by: Hamidreza Hanafi <[email protected]>
---------
Co-authored-by: Hendrik Liebau <[email protected]>
Co-authored-by: Hamidreza Hanafi <[email protected]>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
export default function RootLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) {
|
|
return (
|
|
<html>
|
|
<body>
|
|
<div style={{ maxWidth: 600, margin: '0 auto', padding: 20 }}>
|
|
<h1>Route Cache Keying Regression Test</h1>
|
|
<p style={{ color: '#666', fontSize: 14 }}>
|
|
Reproduces a bug where navigating to an unprefetched route stored
|
|
the route cache entry with an incorrect key, causing subsequent
|
|
prefetches to the same URL to miss the cache and make redundant
|
|
requests. See{' '}
|
|
<a href="https://github.com/vercel/next.js/pull/88863">#88863</a>.
|
|
</p>
|
|
<p style={{ color: '#666', fontSize: 14 }}>
|
|
This test relies on the staleTimes feature to keep route cache
|
|
entries alive across navigations. The client cache currently only
|
|
writes segment data during prefetches, not navigations, so
|
|
staleTimes is needed to preserve the entries for reuse. Once
|
|
navigation-time caching is supported more broadly, this test could
|
|
use a simpler pattern.
|
|
</p>
|
|
<hr />
|
|
{children}
|
|
</div>
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|