next.js
a7877d77 - Bugfix: Incorrect search params stored in cache (#94144)

Commit
60 days ago
Bugfix: Incorrect search params stored in cache (#94144) The route cache write was keying entries on `renderedSearch` — the search string the server actually used to render the page — but lookups use the requested URL's search component. These two are not equivalent: for any search-invariant route (e.g. a static page), `renderedSearch` is `''` regardless of what the request URL carried. The result was that a request for `/a?foo=bar` against a static page parked the cache entry at vary path `(/a, '', null)` — the same slot a clean `/a` lookup keys to. The entry's stored `canonicalUrl` came from the requesting URL (`/a?foo=bar`), so a later `router.push('/a')` or `router.replace('/a')` would hit that slot and restore the stale search string into the browser address bar, `window.location`, and `useSearchParams()`. The fix keys cache writes on the request URL's search, not `renderedSearch`. Entries now sit at the slot keyed by the request that wrote them, so a lookup for a different search variant doesn't find them. Regression test covers the reproduction from the user repo linked in the bug reports. Closes #91658 Closes #92187 <!-- NEXT_JS_LLM_PR -->
Author
Parents
Loading