Skip to content

fix: let useConfig() inside UI components take precedence upon client-side navigation (vikejs/vike#3525) - #251

Merged
brillout merged 1 commit into
mainfrom
claude/sharp-goodall-t1gcwp
Sep 25, 2026
Merged

brillout merged 1 commit into
mainfrom
claude/sharp-goodall-t1gcwp

Conversation

@brillout

@brillout brillout commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Fixes the vike-solid side of vikejs/vike#3525. The same bug is fixed in vike-react by vikejs/vike-react#230.

Bug

Upon client-side navigation, a title set by useConfig() (or <Config>) inside a UI component got overwritten by the title set by +data() (via useConfig()) or by +title.

Cause: Solid renders the new page synchronously inside setPageContext(). During that render, components apply their settings to the DOM directly, because '_headAlreadySet' in pageContext is always true on the client. Right after, onRenderClient() applied the +data()/+config settings, overwriting the components' values.

Fix

onRenderClient() now applies the +data()/+config head settings before rendering the page upon client-side navigation. The settings components apply while rendering then take precedence, which matches SSR (components > Vike hooks > page settings > global settings). There's no visible flash, since the page renders synchronously in the same task.

Why not reuse vike-react's approach (store the value in pageContext._configFromHook while rendering, apply it afterwards): usePageContext() returns a Solid store. The store holds a copy of pageContext's properties and ignores writes made through it, so components can't reach pageContext._configFromHook or observe _headAlreadySet changing without extra workarounds.

Tests (examples/full)

  • /images: <Image> now sets <Config title>, mirroring vike-vue's example, and a new +data() sets a title via useConfig(). Tests check that the component's title wins in the HTML, after hydration, and after client-side navigation. They also check that the title doesn't leak to the next page.
  • Without the fix, useConfig() in UI components upon client-side navigation fails with expected 'Images' to equal 'Image created by Romuald Brillout'.
  • Locally: all e2e tests pass (full and solid-query, dev and preview), as do test:types, lint and format:check.

Related PRs

🤖 Generated with Claude Code

https://claude.ai/code/session_016vKLUPaAR8j8CqQfKQEa6M

…-side navigation (vikejs/vike#3525)

Upon client-side navigation, the settings set by useConfig() (or <Config>)
inside UI components were applied to the DOM while rendering, and then
overwritten by onRenderClient() applying the settings set by +data() or
+config.

Since Solid renders the page synchronously upon setPageContext(), we now
apply the settings of +data() and +config before rendering the page, so that
the settings applied by UI components while rendering take precedence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016vKLUPaAR8j8CqQfKQEa6M
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.

2 participants