Files
e9c4f4289d Fix route cache keying for unprefetched navigations (#90400)
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]>
2026-02-24 07:39:39 +01:00

38 lines
1.3 KiB
TypeScript

import Link from 'next/link'
import { LinkAccordion } from '../../components/link-accordion'
export default function FeedPage() {
return (
<div>
<div id="feed-page">Feed page</div>
<h2>Step 1: Navigate without prefetch</h2>
<p style={{ color: '#666', fontSize: 14 }}>
Click this link to navigate to the photo page. Since prefetching is
disabled, the client has no cached data for this route and will fetch
everything from the server. The response is then stored in the route
cache for future use.
</p>
<p>
<Link href="/photo/1" prefetch={false} id="link-no-prefetch">
Go to photo 1 (no prefetch)
</Link>
</p>
<h2>Step 3: Reveal a prefetched link</h2>
<p style={{ color: '#666', fontSize: 14 }}>
After navigating to the photo page and back, toggle this checkbox to
reveal a prefetched link to the same URL. The prefetch system should
find the route data already in the cache from step 1 — no new network
requests should be needed. If the cache key was stored incorrectly, this
will trigger a redundant prefetch request.
</p>
<p>
<LinkAccordion href="/photo/1">
Go to photo 1 (prefetched)
</LinkAccordion>
</p>
</div>
)
}