Skip to content

fix: decode static template references once, as Vue does - #330

Merged
JuroOravec merged 1 commit into
mainfrom
fix/static-reference-decoding
Oct 24, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/static-reference-decoding

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What was wrong

In a component that uses Vue, these read differently from Vue and the
browser:

  1. A written ( showed (:

    <p title="&amp;#40;">&amp;#40;</p>
    

    Vue and the browser show &#40; in both places, because each reference
    decodes once. The patched vize_atelier_core code generator decoded
    numeric references a second time in escape_js_string, on text the
    parser had already decoded. The S2 emitter matched that for &#40; and
    &#41; only (decode_escaped_numeric_parenthesis).

  2. On S2, a static <component is="a&amp;b"> wrote "a&amp;b", without
    decoding or escaping the value. Vue writes "a&b".

  3. On S2, a dynamic slot name that is not JavaScript, such as
    #[x&amp;y] or v-slot:[n&amp;m], wrote { []: ... }, which is not
    valid JavaScript either. A dynamic argument is part of the attribute
    name, so &amp; stays as written. Vue reports an invalid expression.

  4. On S2, a static style was split at ; before it was decoded, so
    style="font-family:&quot;A B&quot;,serif" lost everything after the
    first &quot;. Vue decodes first.

  5. On vize_atelier_core, a static is was written into the string
    literal without escaping, so is="a&quot;b" gave invalid JavaScript.

  6. On S2, a kept comment decoded its references, where Vue keeps a
    comment as written. Citry drops comments, so only the two lanes'
    agreement changes.

The fix

  • vize_atelier_core (codegen/helpers.rs): escape_js_string escapes
    the text it is given without decoding it. Its callers pass text and
    attribute values that the parser has already decoded, and names and
    comments, which Vue never decodes.
  • vize_s1_to_s2 (emit/entity.rs): every decoder reads each reference
    once; the parenthesis special case is gone.
  • vize_s1_to_s2 (emit/builtin.rs): a static is goes through
    escape_js_attribute_string.
  • vize_s1_to_s2 (emit/create_slots/entry.rs, emit/slots/params.rs):
    a dynamic slot name whose prefixing fails is refused instead of being
    written as an empty string, so Citry compiles the template with
    vize_atelier_core, which reports InvalidExpression, and Citry shows
    that to the user.
  • vize_s1_to_s2 (emit/style.rs, emit/children.rs): a static style
    is decoded before it is split, and a kept comment is written as written.
  • vize_atelier_core (codegen/element/block.rs, inline.rs): a static
    is is escaped for its string literal.
  • The patched crates and the compiler identity move to 0.420.0+citry.6,
    because the compiled code changes. Both README.citry.md files list the
    change.

A legacy name that a letter or digit follows in an attribute value, such
as title="a&notin", already stays as written on both lanes, as the
browser reads it. Vue's compiler writes a¬in there. The server HTML
and the browser are the reference, so this keeps the browser's reading,
and a new test locks it.

Tests

crates/citry_vue_compiler/tests/static_reference_entities.rs runs each
case on S2 alone and on the vize_atelier_core lane alone. It covers the
single decode in text and attributes (including &amp;#x22;), a&notin
in an attribute and in text, a static is (with &amp; and &quot;),
a static style with &quot;, and a kept comment. It also checks that
S2 refuses both dynamic slot names and that vize_atelier_core reports
InvalidExpression for them. Each case except a&notin fails on main.

Replaying the 1,432 compile requests recorded from the citry and
citry_ui test suites gives the same result as on main: no template in them
writes a doubled reference, so their code is unchanged.

The existing vize_s1_to_s2 and vize_atelier_core test targets have the
same results as before (emit_if, metamorphic and
dynamic_v_model_argument fail on main too).

Changelog: a Fixes line in CHANGELOG.md.

Not fixed here

S2 condenses whitespace in text before it decodes it, where Vue decodes
first, so <p>a&#10;&#10;b</p> keeps two line feeds on S2 where Vue
writes one space. Changing that order touches the source positions that
Citry's authored text plan records for each condensed run, so it needs
its own change.

🤖 Generated with Claude Code

In a component that uses Vue, a written `&amp;#40;` in text or a static
attribute value showed `(`, where Vue and the browser show `&#40;`: the
vize_atelier_core code generator decoded numeric references a second
time in escape_js_string, and the S2 emitter matched it for `&#40;` and
`&#41;`. Both lanes now decode each reference once.

The S2 emitter also decodes a static `style` before splitting it at `;`,
so `&quot;` inside a declaration stays in it, writes a kept comment as
written, and decodes and escapes a static `is` on `<component>`, which
vize_atelier_core now escapes too. S2 refuses a dynamic slot name that
is not JavaScript, such as `#[x&amp;y]`, so the vize_atelier_core code
generator reports Vue's invalid-expression error instead of S2 writing an
empty name. A legacy name that a letter follows in an attribute value
(`title="a&notin"`) stays as written, as in the browser (Vue's compiler
writes `a¬in`); a new test locks that on both lanes.

The patched Vize crates and the compiler identity move to
0.420.0+citry.6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 1b64f71 into main Oct 24, 2026
24 of 30 checks passed
@JuroOravec
JuroOravec deleted the fix/static-reference-decoding branch October 24, 2026 16:02
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.

1 participant