Don't suspend client params on shallow URL updates (#99611)
With Cache Components enabled, a client page or layout that reads
`use(params)` or `use(searchParams)` showed the nearest Suspense
fallback on every `history.pushState` / `history.replaceState`, and when
going back and forward between those entries. The content was hidden for
a few hundred milliseconds each time, so a focused input lost focus and
dropped keystrokes.
Since the `params` and `searchParams` are already known on the client
during a render triggered by a navigation, there's no reason for them to
suspend. They were only suspending because we created a fresh promise on
each render.
We can instead mark the promise as fulfilled up front, by setting the
same `status` and `value` fields React sets once it has tracked a
promise. This is the internal protocol React uses to synchronously
unwrap resolved promises.
Ideally we would also avoid recomputing them on every render, only when
the router tree actually changes, but we can address that separately.
Thanks to @controversial, who found the cause and wrote the tests in
#99537.
Fixes #99512.
Co-authored-by:
Luke Deen Taylor <10377391+controversial@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment