Skip to content

fix: write a v-pre element's :x attribute on the server - #413

Merged
JuroOravec merged 2 commits into
mainfrom
fix/v-pre-colon-attribute
Oct 25, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/v-pre-colon-attribute

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Fixes #394. In a component that uses Vue, an element inside v-pre keeps Vue syntax as plain attributes, such as :x="y". The server declined those names, so the element's parent became a shell, and the page showed the element without the attribute until Vue built it.

Why the server can write it

  • Vue sets it as an attribute. I read Vue 3.5.44's patchProp and shouldSetAsProp: a key starting with : is not class or style, not a listener, and not a . or ^ modifier. ":x" in el is false (Chrome 155 gave false for all 13 names tried, on HTML and SVG). So Vue sets it with setAttribute.
  • Hydration keeps the server's text. It patches such a name only for forcePatch keys ending in value, for custom elements, and for keys listed in dynamicProps. Each of those gives the same text the server wrote.
  • Vize's render code keeps { ":x": "y" } as written.
  • In headless Chrome with Vue's dev build, server HTML from this branch hydrated with the DOM unchanged and no warnings, while a title mismatch control did warn.

The change

  • One shared rule: is_plain_attribute_name is used by client_attribute, which writes the hydrated HTML, and by the token check. It accepts lowercase letters, digits, -, _ and :, starting with a letter, or with : followed by a lowercase letter.
  • Shell contents: is_static_attribute_name accepts the same leading :.
  • Still declined:
    • names starting with @ or #, because browsers disagree on whether setAttribute accepts them (current Chrome does);
    • . and ^, which are Vue's prop and attribute modifiers;
    • :X, ::x, :_x and :x.prop.
  • The token check: because it shares the rule, a page with :x keeps the fast token check rather than falling back to the full parse.

Tests

  • Rust:
    • the written HTML for a v-pre table and a v-pre div with :x;
    • @click still declined, while the shell's contents keep :x;
    • the name rule's edge cases.
    • Without the fix, the first test fails with <td data-allow-mismatch="children"><b title="t">A</b>.
  • Python: the table page hydrates with nothing declined.
  • Vue render parity check: for the v-pre tests, 26 pages, 0 mismatches and 0 Vue errors. The full file's run still shows the unrelated deep-page RangeError that fix: give the Vue parity check's Node render enough stack for deep pages #408 fixes.

Cost

The name check runs for each attribute the server writes; the change adds one comparison for a name that does not start with a lowercase letter.

Found while reviewing, not changed

Inside v-pre, <input :value='y'> gets a literal v-citry-vue-owned="'value'" attribute, in the render code and now in the server HTML too; the same happens for <option :selected>. vue_owned_native_marker (citry/_vue/capture.py) treats :value as a binding even under v-pre. Server and browser match, so nothing breaks, but it deserves its own issue.

🤖 Generated with Claude Code

Fixes #394. In a component that uses Vue, an element inside `v-pre` keeps
Vue syntax as plain attributes, such as `:x="y"`. The server renderer
wrote only attribute names that start with a lowercase letter, so it
declined `:x`, and the element's parent became a shell that Vue built in
the browser:

    <td data-allow-mismatch="children"><b title="t">A</b></td>

`:` means nothing to Vue's `patchProp`, and no element has a member of
that name, so Vue sets `:x` with `setAttribute`. Hydration keeps the
server's text for a plain attribute, so the server can write it. The
three name checks now accept a name that starts with `:` followed by a
lowercase letter: `client_attribute` for the hydrated HTML and the token
check share one rule (`is_plain_attribute_name`), and
`is_static_attribute_name` covers a shell's contents. Names starting with
`@` or `#` stay declined, because browsers disagree on whether
`setAttribute` accepts them (current Chrome does), and `.` and `^` stay
declined as Vue's prop and attribute modifiers.

Tests: a Rust test locks the written HTML for a `v-pre` table and a
`v-pre` div with `:x`, and that `@click` is still declined while the
shell's contents keep `:x`; another checks the name rule's edge cases;
a Python test checks the table page hydrates with nothing declined. The Vue render parity
check reports 0 mismatches for the `v-pre` tests, so the written HTML is
what Vue's own server renderer writes.

The name check runs for each attribute the server writes; the change adds
one comparison for a name that does not start with a lowercase letter.
Because the token check uses the same rule, a page with `:x` keeps the
fast token check instead of falling back to the full parse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit cd52b13 into main Oct 25, 2026
19 of 31 checks passed
@JuroOravec
JuroOravec deleted the fix/v-pre-colon-attribute branch October 25, 2026 15:27
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.

Server HTML leaves a v-pre element's :x attribute to the browser

1 participant