Repository navigation
fix(solid): keep useParams() current after client navigation - #709
Merged
Merged
Conversation
The generated client passed the params to ParamsContext.Provider through a getter over the routeParams signal. Solid's provider reads its value once, inside untrack, so every useParams() call received the first page's params, even on pages created after a navigation. Update a stable params object in place, the same way shared data is updated, so the object returned by useParams() stays reactive and current. Fixes voidzero-dev#708
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #708.
In Solid pages,
useParams()keeps returning the first page's params after a client-side navigation. On/posts/[slug], clicking a<Link>from/posts/ato/posts/bupdates the page props, butconst params = useParams(); params.slugstill reads"a".useRouter().paramsis correct.The generated client passes the params with
get value() { return routeParams(); }, but Solid's context provider readsvalueonce, insideuntrack. The context keeps the first object, even for pages created after a navigation.What changed
packages/solid/src/plugin-pages.ts: params are now a stablecreateMutableobject updated in place, the same way shared data already is. ThereplaceSharedhelper is nowreplaceInPlace(target, next)and is used for both. This matches the Svelte fix in fix(svelte): keep useParams() current when navigating within the same page #610.routeParamssignal stays for the router facade and thesameParamscheck, souseRouter().paramsis unchanged.Tests
packages/solid/test/integration/use-params-navigation.test.ts: runs the real generated client in Chromium with a page and a layout that calluseParams(), clicks a<Link>fromatob, and checks that both showbwithout a document reload. A small Vite middleware stands in for the Worker's page responses. It fails without the fix.To check
useParams()now always returns the same object for the life of the app, asuseShared()already does.