Skip to content

Bugfix: Incorrect search params stored in cache - #94144

Merged
timneutkens merged 1 commit into
canaryfrom
acdlite/fix-route-cache-search-params
May 27, 2026
Merged

timneutkens merged 1 commit into
canaryfrom
acdlite/fix-route-cache-search-params

Conversation

@acdlite

@acdlite acdlite commented May 27, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: 84ba3e8
View workflow run

@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 84ba3e8

@acdlite
acdlite requested a review from samselikoff May 27, 2026 02:59
@acdlite
acdlite marked this pull request as ready for review May 27, 2026 03:00
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
@acdlite
acdlite force-pushed the acdlite/fix-route-cache-search-params branch from 7cea932 to 84ba3e8 Compare May 27, 2026 03:01
@timneutkens
timneutkens merged commit a7877d7 into canary May 27, 2026
164 of 165 checks passed
@timneutkens
timneutkens deleted the acdlite/fix-route-cache-search-params branch May 27, 2026 09:31
m-kawafuji pushed a commit to m-kawafuji/next.js that referenced this pull request Aug 8, 2026
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 vercel#91658
Closes vercel#92187

<!-- NEXT_JS_LLM_PR -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants