searchParams access through a Proxy to catch missing-key reads (#93549)
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.
Getting Started
Used by some of the world's largest companies, Next.js enables you to create full-stack web applications by extending the latest React features, and integrating powerful Rust-based JavaScript tooling for the fastest builds.
- Visit our Learn Next.js course to get started with Next.js.
- Visit the Next.js Showcase to see more sites built with Next.js.
Documentation
Visit https://nextjs.org/docs to view the full documentation.
Community
The Next.js community can be found on GitHub Discussions where you can ask questions, voice ideas, and share your projects with other people.
To chat with other community members you can join the Next.js Discord server.
Do note that our Code of Conduct applies to all Next.js community channels. Users are highly encouraged to read and adhere to it to avoid repercussions.
Contributing
Contributions to Next.js are welcome and highly appreciated. However, before you jump right into it, we would like you to review our Contribution Guidelines to make sure you have a smooth experience contributing to Next.js.
Good First Issues:
We have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place for newcomers and beginners alike to get started, gain experience, and get familiar with our contribution process.
Security
If you believe you have found a security vulnerability in Next.js, we encourage you to responsibly disclose this and NOT open a public issue.
To participate in our Open Source Software Bug Bounty program, please email [email protected]. We will add you to the program and provide further instructions for submitting your report.