Skip to content

fix: let the app's htmlAttributes/bodyAttributes take precedence over the ones set by Vike extensions - #228

Merged
brillout merged 1 commit into
mainfrom
claude/tag-attributes-precedence-ljv9nc
Sep 19, 2026
Merged

brillout merged 1 commit into
mainfrom
claude/tag-attributes-precedence-ljv9nc

Conversation

@nitedani

@nitedani nitedani commented Sep 18, 2026

Copy link
Copy Markdown
Member

Problem

The values of the cumulative settings +htmlAttributes and +bodyAttributes were merged in the order Vike provides them (most specific value first, values set by Vike extensions last), with the last value winning upon conflict. So, upon conflict:

  • a value set by a Vike extension overrode the app's value, and
  • a value set by +config.js overrode the value set by +htmlAttributes.js / +bodyAttributes.js.

That's the opposite of how every other Vike setting resolves. (The order of cumulative values is pinned by Vike's playground test test/playground/pages/config-meta/cumulative/.)

Fix

The root cause is in getHeadSetting() (packages/vike-react/src/integration/getHeadSetting.tsx): for cumulative settings, it concatenated the config values (sorted by decreasing precedence) with the useConfig() values (highest precedence, appended last), so no merge order could get both right.

getHeadSetting() now returns the values of a cumulative setting sorted by increasing precedence: the values set by Vike extensions first, then the app's values (the most specific one last), then the values set by useConfig(). Merging them in order, as mergeTagAttributesList() in onRenderHtml.tsx does, thus yields the most specific value. Values set by useConfig() keep the highest precedence (unchanged).

Only htmlAttributes and bodyAttributes go through that code path (Head is rendered directly from pageContext.config.Head, in Vike's order).

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01MdJwhUKSfXPVuSvXyxBpr7

…over the ones set by Vike extensions

For cumulative settings, `getHeadSetting()` returned the values in the order Vike provides them (most specific value first, values set by Vike extensions last) followed by the values set by `useConfig()`, and the tag attributes were merged in that order with the last value winning upon conflict. Consequently, upon conflict, a value set by a Vike extension would override the app's value, and a value set by `+config.js` would override the value set by `+htmlAttributes.js`.

`getHeadSetting()` now returns the values of cumulative settings sorted by increasing precedence (values set by Vike extensions first, the app's most specific value last, then the values set by `useConfig()`), so that merging them in order yields the value with the highest precedence. Values set by `useConfig()` keep the highest precedence.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MdJwhUKSfXPVuSvXyxBpr7
@nitedani
nitedani force-pushed the claude/tag-attributes-precedence-ljv9nc branch from 42eac6c to 5efce2f Compare September 19, 2026 07:10
@brillout
brillout merged commit 42eb633 into main Sep 19, 2026
7 checks passed
@brillout
brillout deleted the claude/tag-attributes-precedence-ljv9nc branch September 19, 2026 07:30
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.

3 participants