Skip to content

fix(solid): keep useParams() current after client navigation - #709

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
yujiym:fix/solid-use-params
Nov 4, 2026
Merged

cpojer merged 1 commit into
voidzero-dev:mainfrom
yujiym:fix/solid-use-params

Conversation

@yujiym

@yujiym yujiym commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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/a to /posts/b updates the page props, but const params = useParams(); params.slug still reads "a". useRouter().params is correct.

The generated client passes the params with get value() { return routeParams(); }, but Solid's context provider reads value once, inside untrack. 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 stable createMutable object updated in place, the same way shared data already is. The replaceShared helper is now replaceInPlace(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.
  • The routeParams signal stays for the router facade and the sameParams check, so useRouter().params is unchanged.

Tests

  • New packages/solid/test/integration/use-params-navigation.test.ts: runs the real generated client in Chromium with a page and a layout that call useParams(), clicks a <Link> from a to b, and checks that both show b without 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, as useShared() already does.

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

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@cpojer
cpojer merged commit e3c8a15 into voidzero-dev:main Nov 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@void/solid: useParams() keeps the first page's params after client-side navigation

2 participants