Repository navigation
fix: write a v-pre element's :x attribute on the server - #413
Merged
Merged
Conversation
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]>
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.
Fixes #394. In a component that uses Vue, an element inside
v-prekeeps 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
patchPropandshouldSetAsProp: a key starting with:is notclassorstyle, not a listener, and not a.or^modifier.":x" in elis false (Chrome 155 gave false for all 13 names tried, on HTML and SVG). So Vue sets it withsetAttribute.forcePatchkeys ending invalue, for custom elements, and for keys listed indynamicProps. Each of those gives the same text the server wrote.{ ":x": "y" }as written.titlemismatch control did warn.The change
is_plain_attribute_nameis used byclient_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.is_static_attribute_nameaccepts the same leading:.@or#, because browsers disagree on whethersetAttributeaccepts them (current Chrome does);.and^, which are Vue's prop and attribute modifiers;:X,::x,:_xand:x.prop.:xkeeps the fast token check rather than falling back to the full parse.Tests
v-pretable and av-prediv with:x;@clickstill declined, while the shell's contents keep:x;<td data-allow-mismatch="children"><b title="t">A</b>.v-pretests, 26 pages, 0 mismatches and 0 Vue errors. The full file's run still shows the unrelated deep-pageRangeErrorthat 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 literalv-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:valueas a binding even underv-pre. Server and browser match, so nothing breaks, but it deserves its own issue.🤖 Generated with Claude Code