Commit de37cd7
authored
Track
Under `experimental.varyParams`, when a page reads `searchParams` from a
URL without a query string, `createVaryingSearchParams` previously
returned a plain object whose only own properties were getters for keys
that already existed in the URL. With no keys present, that's an empty
`{}` — so `Object.entries`, spread, `in` checks, and missing-key reads
(e.g. `searchParams.foo` returning `undefined`) all silently no-opped
without registering an access. The segment ended up keyed at the
`Fallback` search slot in the segment cache, where it shadowed
subsequent prefetches with non-empty search params via `Fallback`
resolution, silently serving the stale empty-query cache entry on
navigation.
This switches the implementation to a `Proxy` with `get`, `has`, and
`ownKeys` traps that record the `'?'` sentinel on every string access.
Search params have no fixed schema, so any access — including
missing-key reads, `in` checks, and enumeration — must register as
varying. The `get` trap has one carve-out: `.then` reads are skipped
when no `then` key exists on the target, since `Promise.resolve` and
React Flight probe `.then` to test thenability and those probes
shouldn't count as user dependencies. As a trade-off, a page that reads
`searchParams.then` to compute its output and is prefetched without a
`then` key won't register the access — accepted because `then` is
reserved by the Promise protocol and essentially never used as a query
parameter name.
The added regression test prefetches the no-query URL first and asserts
that a subsequent `?foo=1` prefetch still triggers a fresh request.
Without the fix the lookup resolves to the empty-query cache entry
through `Fallback`, no request is initiated, and the test times out
waiting for one.searchParams access through a Proxy to catch missing-key reads (vercel#93549)1 parent c06d94b commit de37cd7
3 files changed
Lines changed: 87 additions & 14 deletions
File tree
- packages/next/src/server/app-render
- test/e2e/app-dir/segment-cache/vary-params
- app/(main)/search-params
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
311 | 313 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
318 | 328 | | |
319 | 329 | | |
320 | 330 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
Lines changed: 59 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
253 | 303 | | |
254 | 304 | | |
255 | 305 | | |
| |||
600 | 650 | | |
601 | 651 | | |
602 | 652 | | |
603 | | - | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
604 | 662 | | |
605 | 663 | | |
606 | 664 | | |
| |||
0 commit comments