Commit a7877d7
authored
Bugfix: Incorrect search params stored in cache (vercel#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 vercel#91658
Closes vercel#92187
<!-- NEXT_JS_LLM_PR -->1 parent 67d5f96 commit a7877d7
12 files changed
Lines changed: 136 additions & 2 deletions
File tree
- packages/next/src/client/components
- router-reducer
- reducers
- segment-cache
- test/e2e/app-dir/segment-cache/stale-search-params-on-replace-regression
- app
- dummy-page-1
- dummy-page-2
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1636 | 1636 | | |
1637 | 1637 | | |
1638 | 1638 | | |
| 1639 | + | |
1639 | 1640 | | |
1640 | 1641 | | |
1641 | 1642 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
| 488 | + | |
488 | 489 | | |
489 | 490 | | |
490 | 491 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1141 | 1141 | | |
1142 | 1142 | | |
1143 | 1143 | | |
| 1144 | + | |
1144 | 1145 | | |
1145 | 1146 | | |
1146 | 1147 | | |
| |||
1158 | 1159 | | |
1159 | 1160 | | |
1160 | 1161 | | |
1161 | | - | |
1162 | 1162 | | |
1163 | 1163 | | |
1164 | | - | |
| 1164 | + | |
1165 | 1165 | | |
1166 | 1166 | | |
1167 | 1167 | | |
| |||
1797 | 1797 | | |
1798 | 1798 | | |
1799 | 1799 | | |
| 1800 | + | |
1800 | 1801 | | |
1801 | 1802 | | |
1802 | 1803 | | |
| |||
1854 | 1855 | | |
1855 | 1856 | | |
1856 | 1857 | | |
| 1858 | + | |
1857 | 1859 | | |
1858 | 1860 | | |
1859 | 1861 | | |
| |||
2347 | 2349 | | |
2348 | 2350 | | |
2349 | 2351 | | |
| 2352 | + | |
2350 | 2353 | | |
2351 | 2354 | | |
2352 | 2355 | | |
| |||
2395 | 2398 | | |
2396 | 2399 | | |
2397 | 2400 | | |
| 2401 | + | |
2398 | 2402 | | |
2399 | 2403 | | |
2400 | 2404 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| 440 | + | |
440 | 441 | | |
441 | 442 | | |
442 | 443 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
| 239 | + | |
238 | 240 | | |
239 | 241 | | |
240 | 242 | | |
| |||
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
| 261 | + | |
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| |||
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| 282 | + | |
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
| |||
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| 296 | + | |
292 | 297 | | |
293 | 298 | | |
294 | 299 | | |
| |||
344 | 349 | | |
345 | 350 | | |
346 | 351 | | |
| 352 | + | |
347 | 353 | | |
348 | 354 | | |
349 | 355 | | |
| |||
370 | 376 | | |
371 | 377 | | |
372 | 378 | | |
| 379 | + | |
373 | 380 | | |
374 | 381 | | |
375 | 382 | | |
| |||
409 | 416 | | |
410 | 417 | | |
411 | 418 | | |
| 419 | + | |
412 | 420 | | |
413 | 421 | | |
414 | 422 | | |
| |||
429 | 437 | | |
430 | 438 | | |
431 | 439 | | |
| 440 | + | |
432 | 441 | | |
433 | 442 | | |
434 | 443 | | |
| |||
496 | 505 | | |
497 | 506 | | |
498 | 507 | | |
| 508 | + | |
499 | 509 | | |
500 | 510 | | |
501 | 511 | | |
| |||
517 | 527 | | |
518 | 528 | | |
519 | 529 | | |
| 530 | + | |
520 | 531 | | |
521 | 532 | | |
522 | 533 | | |
| |||
534 | 545 | | |
535 | 546 | | |
536 | 547 | | |
| 548 | + | |
537 | 549 | | |
538 | 550 | | |
539 | 551 | | |
| |||
565 | 577 | | |
566 | 578 | | |
567 | 579 | | |
| 580 | + | |
568 | 581 | | |
569 | 582 | | |
570 | 583 | | |
| |||
test/e2e/app-dir/segment-cache/stale-search-params-on-replace-regression/app/dummy-page-1/page.tsx
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
test/e2e/app-dir/segment-cache/stale-search-params-on-replace-regression/app/dummy-page-2/page.tsx
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments