Skip to content

fix: read v-pre content as plain, as Vue 3.5 does - #525

Merged
JuroOravec merged 2 commits into
mainfrom
fix/v-pre-plain
Oct 28, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/v-pre-plain

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What this fixes

Vue 3.5 reads an element with v-pre, and everything inside it, as written: directives stay plain attributes and tags stay plain elements. Citry differed in two places (#515):

  1. The template parser rejected Vue-only syntax inside v-pre (v-once, <transition>, @click.bogus), so templates Vue accepts failed to load.
  2. vize compiled some tags inside v-pre as live Vue: <slot> as an outlet, <component is> as a dynamic component, <teleport>, <keep-alive>, and <transition> as built-ins.

Changes

  • Parser (parser.rs): a per-entry in_v_pre flag on the tag stack. For an HTML element carrying v-pre or inside one, the Vue-only checks are skipped: listener modifiers, reserved names, v-once/v-memo, directive shapes, Vue built-in tags, and a Vue binding beside a Python value. The order of the remaining checks is unchanged. Citry tags (<c-*>) keep all their checks, and Vue slot syntax on a component's direct child keeps its check inside v-pre. v-pre written with an argument or modifiers (v-pre.x), which Vue also reads as v-pre, is now rejected, so Citry and Vue cannot disagree about which content is read as written. No grammar change.
  • vize S2 lane (third_party/rust/vize_s1_to_s2/src/lower/element.rs, patched copy bumped to 0.420.0+citry.7 everywhere): inside v-pre and on the element that opens it, <slot>, <component>, the built-ins, and any component name stay plain elements, and is is dropped from a plain <component>. Each case matches @vue/compiler-dom 3.5.42's output exactly with Citry's options (tests/citry_v_pre_tags.rs). README.citry.md lists the change.
  • vize fallback lane: vize falls back to its older code generator when the S2 lane declines a template, and that lane types tags in vize_armature, which Citry has not patched. Citry now refuses a v-pre template the S2 lane declines (V_PRE_NEEDS_S2_LANE), probing S2 with the compile's own options only when the template text contains v-pre. Patching vize_armature is Make vize's fallback lane follow Vue's v-pre rules #519 (v1.1).
  • Citry's metadata walk (citry_vue_compiler/src/lib.rs) no longer reports a <slot> or <template v-slot> under v-pre as an outlet or a fill, so no fill can target one. It reads v-pre from the opening tag's source, because the vize parser it walks removes v-pre from the props.
  • v-once / v-memo (_vue/compiler.py): without v-pre in the template they are refused by spelling, as before. In a template with v-pre they are refused by what they compile to, so a v-once inside v-pre renders as a plain attribute.
  • A Vue-typed tag carrying v-pre with Citry values (<slot v-pre>{{ x }}</slot>, <component v-pre>, a built-in, or a capitalized component name; SVG's camelCase elements are native): Citry compiles such an element itself as live Vue, so rendering now fails with advice to put v-pre on an element around it.

Custom elements

An earlier version of this branch let the server renderer write custom element names (tags with -). The reviewer showed that a custom element defined before hydration, which adds its own children in connectedCallback, then mismatches on hydration, which the browser-built path avoids. That change is reverted: custom elements, including <keep-alive> inside v-pre, stay built by the browser as before. No Citry UI component or rendered docs example writes a plain custom element.

Tests

  • Rust: parser tests (each Vue-only case loads inside v-pre, still fails outside it, <c-*> tags keep their checks, v-pre.x and v-pre:x are rejected, slot syntax on a component's child keeps its check); the vize regression test; citry_vue_compiler tests for the outlet walk (including title="v-pre", title= v-pre, data-v-pre, and a multi-line opening tag) and for the S2 refusal, both firing and not firing.
  • Python (test_vue_v_pre_plain.py): each tag renders as written; <keep-alive> is built by the browser; v-once renders as an attribute; a parent fill is not placed into a <slot> under v-pre; Vue-typed tags carrying v-pre with Citry values are refused, and an SVG <foreignObject v-pre> renders.
  • Browser: the tags hydrate like a client mount.
  • render_body_snapshots.json changes only hashes, from the version bump.

Checks: the parser and Vue compiler crate tests, the vize regression test, cargo fmt and clippy; the citry and Citry UI suites (13,696 passed); the related browser tests; mypy (also --platform linux); ruff; scripts/validate.py. The Vue render parity check over the whole non-browser corpus: 0 mismatches, 0 Vue errors. One Citry UI type-check test fails in my local environment only (its ty is 0.0.90 where main now needs 0.0.91). An independent reviewer ran three rounds against Vue 3.5.42's compiler and a browser.

Not covered

  • @... attributes inside v-pre (such as @click) still make the server leave that element for the browser to build, which cannot set an attribute named @click. That is unchanged by this PR.
  • Listed in Make vize's fallback lane follow Vue's v-pre rules #519 for v1.1: the fallback lane; is="vue:..." and v-slot inside v-pre; a custom element carrying v-pre with Citry values, which still compiles as a component.

Docs and changelogs

  • vue/limits.md and vue/props-and-events.md now say the built-ins and v-once/v-memo fail outside v-pre.
  • A Fixes entry in CHANGELOG.md; two lines in packages/py/citry_core/CHANGELOG.md.

Fixes #515.

🤖 Generated with Claude Code

Inside v-pre, Vue reads directives as plain attributes and tags as plain
elements. Citry's template parser still ran its Vue-only checks there, so
v-once, <transition>, or @click.bogus inside v-pre failed to load, and
vize compiled <slot>, <component is>, <teleport>, <keep-alive>, and
<transition> inside v-pre as live Vue.

- The template parser skips the Vue-only checks for an HTML element that
  carries v-pre or sits inside one, and rejects v-pre written with an
  argument or modifiers. Citry tags keep their checks, and Vue slot syntax
  on a component's direct child keeps its check inside v-pre.
- vize's S2 lane (patched, now 0.420.0+citry.7) keeps those tags plain
  inside v-pre and on the element that opens it, and drops `is` from a
  plain <component>, matching @vue/compiler-dom 3.5.42.
- Citry's Vue compiler refuses (V_PRE_NEEDS_S2_LANE) a v-pre template
  that only vize's fallback lane would compile, since that lane still
  reads those tags as live (#519), and its metadata walk no longer
  reports a <slot> or fill under v-pre as an outlet.
- v-once and v-memo inside v-pre render as plain attributes; elsewhere
  they are still refused.
- When v-pre sits on a Vue-typed tag whose contents hold Citry values,
  rendering fails with advice to put v-pre on an element around it.

Fixes #515.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Inside v-pre, the template parser and vize still treat Vue syntax as live Vue

1 participant