Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Regression in mounting components #461

Merged
merged 5 commits into from
Jan 17, 2024
Merged

fix: Regression in mounting components #461

merged 5 commits into from
Jan 17, 2024

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Jan 17, 2024

Regression introduced by #457 was detected in the repro-359 test case, where components with a useQueryState failed to capture the correct value on mount, and trailed behind.

  • Add an e2e test case to track across versions & configuration
  • Investigate a fix

Root of the issue

The useEffect introduced in #394 to sync internal state against a reactive useSearchParams hook in order to support WHS in 14.0.3 had a flaw. Actually, 14.0.3 had a flaw too, but we'll come to that in a bit.

The test in #359 exposes differences between the internal state of the useQueryState hook and the URL state (as reflected in a reactive useSearchParams): when a component mounts because of a query state change, and that component also listens for the same query key, its internal state will be fine on mount (due to the state initialisation function taking into account the URL update queue), but the initial useSearchParams will still reflect the stale, not-yet-updated URL. Attempting to sync on that on mount causes the value to trail behind.

Now onto the issue in [email protected]: implementation of the WHS had a bug that didn't call patched history methods made in third party modules like nuqs (and other analytics packages). This caused a known issue to be published, with the resolution of "enable WHS". This would only help make the useSearchParams hook reactive, and we can sync to it, but only in 14.0.3, leading to the ugly hack of version detection that will be removed entirely in v2 (along with support for 14.0.3).

So is 14.0.3, with WHS, subject to 359? Turns out, no. For some reason the tests pass fine there. No idea why, as it theoretically should fail, but since we're going to drop it anyway.. 🤷

Copy link

vercel bot commented Jan 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 10:09pm

Since applying the search params to the URL is deferred,
it causes the 359 regression: on mount, the component
with a useQueryState identical to the one that triggered
its mounting would have a correct internal state, but that
would get overriden by a stale (not yet updated) iSP.

Trying to remove the whole sync logic to see how
previous versions may break, and adding 14.0.5-canary.54
which stabilises WHS for future-proofing until GA.
We'll release a patch fix for the 1.x release line and this
is going straight to the bin in v2, it will only support 14.0.4 onwards.
@franky47 franky47 marked this pull request as ready for review January 17, 2024 22:09
@franky47 franky47 merged commit 6b6d190 into next Jan 17, 2024
16 checks passed
@franky47 franky47 deleted the fix/359-regression branch January 17, 2024 22:27
Copy link

🎉 This PR is included in version 1.15.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant