Fix prefetch loop when a predicted route redirects (#98998)
A full or runtime prefetch (e.g. `router.prefetch(url, { kind: 'full'
})` or `<Link prefetch={true}>`) of a URL that matched a learned route
pattern but is redirected by the server (e.g. `/docs/changelog` →
`/changelog` while `/docs/alpha` renders `[collection]/[...slug]`)
caused the client to re-issue the same prefetch indefinitely, at
whatever rate the network allowed, until the tab was closed.
When the server contradicts a route prediction, the client is supposed
to remember that the URL shape can't be predicted and resolve it on the
server from then on. We were storing this information
(`hasDynamicRewrite`) in the wrong place: on the predicted route cache
entry, rather than the optimistic routing table that's used to generate
predictions.
The fix moves the `hasDynamicRewrite` flag to the optimistic routing
table so it applies to all subsequent optimistic routing predictions.
Fixes #98345.
<!-- NEXT_JS_LLM -->
Showing
This diff is collapsed.
Please
register
or
sign in
to comment