Skip to content

fix: render Citry values inside v-pre as HTML that Vue inserts - #348

Merged
JuroOravec merged 1 commit into
mainfrom
fix/vue-v-pre
Oct 25, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/vue-v-pre

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Fixes #329

What was wrong

Inside an element with v-pre, Citry's own template syntax reached the
page as internal names:

<div v-pre>{{ name }} and {{ 'a' }}</div>

showed {{ $citryPrepared.citryText0 }} and {{ $citryPrepared.citryText1 }}.
A c-title="name" binding, inside the element or on it, failed to compile
with ELEMENT_ATTRS_BINDING_MISMATCH, and so did #c-key on a v-pre row
of a loop.

Citry evaluates its {{ }}, c- bindings, <c-if> and <c-for> in
Python, and hands the values to Vue as data bindings in the Vue template.
Vue does not compile anything inside v-pre, so those bindings stayed as
written.

The fix

Of the two options in the issue, I took the first: inside v-pre, Citry
writes the values it already computed.

A v-pre element that holds only HTML and Vue syntax is left to Vue,
as on main. Citry writes it with v-pre kept, and Vue reads the element
and its contents as written (_v_pre_left_to_vue in
_vue/direct_capture.py). <c-js />, <c-css /> and a transparent
component that holds only written markup count as written markup here.
A <c-if> or <c-for> takes Citry's path, so rows and branches chosen
at render time stay data.

Otherwise Citry handles v-pre itself:

  • The element is written without v-pre (_without_v_pre). Its own
    c- bindings and #c-key then compile as on any element. Citry refuses
    an authored Vue attribute such as :title on the element, which Vue
    would write as a plain attribute under v-pre, and says to move it
    inside. The tag itself compiles as it does on main: Citry's Vue
    compiler (vize) decides whether a tag such as <my-widget> or <slot>
    is a component or a slot whether or not v-pre is set.

  • The contents go out as one block of HTML that reaches the browser as
    data. This is the path a #c-ignore block takes, but the block is not
    pinned, so a later render replaces it with the new values. Vue inserts
    the server's HTML without compiling it. Several things follow:

    • Request values never enter the compiled render function, so text such
      as </script> is safe, and every row of a loop shares one compiled
      definition.
    • An unbalanced Markup value is refused, as everywhere else.
    • Whitespace stays as the server writes it. Vue would squeeze a run of
      spaces into one under v-pre; the server HTML keeps it, as a page
      without Vue does.
    • The block sits between <!--[--> and <!--]--> marker comments
      inside the element. Code that reads the element's child nodes sees
      them. CSS :empty ignores comments.
    • The browser drops a line break written straight after <pre>, but not
      after a marker comment, so Citry drops that one line break from a
      <pre v-pre> or <listing v-pre> block itself.

    The contents are written by the serializer #c-ignore uses
    (_ignored_contents_html). Authored Vue attributes stay plain
    attributes, as v-pre keeps them. A simple = True component and a
    transparent component, such as <c-element>, are written in place,
    together with the slot content the template gives them.
    Citry refuses what Vue would not mount or run there: a child component,
    a <c-slot /> outlet, an Events or browser binding, and a #c-ignore
    element, whose kept contents a later render would replace. The error
    names a built-in by its tag, such as <c-error-fallback>.

  • Where a block of HTML cannot sit, Citry compiles the contents as
    usual and drops only the attribute. These are the places where the
    template parser already refuses #c-ignore:

    • table rows and sections (<table>, <thead>, <tbody>, <tfoot>,
      <tr>, <colgroup>), because the browser moves a block of HTML out of
      them;
    • <svg>, <math> and anything inside them, because the browser
      cannot insert their contents as HTML.

    Vue writes HTML and SVG elements the same way whether or not it
    compiles them, so this gives the same page. Citry refuses contents that hold Vue
    syntax, such as <td :x="y">, or a child component, whose slot content
    Vue would compile. Compiling them would run what v-pre keeps as
    written. A nested v-pre element there gets its own block. The error
    suggests putting v-pre on a <td> or on an element that wraps the
    table or the SVG.

    Text-only elements (<textarea v-pre>, <title v-pre>) follow the same
    rule: the attribute is dropped and their text renders as usual.

  • _vue/capture.py: the step that joins static template nodes keeps a
    v-pre element's closing tag as its own node, as it does for
    #c-ignore, so the assembler can find where the contents end.

  • _vue/leaf_program.py: the fast path for templates with no child
    components leaves a template with v-pre to the general assembler, as
    it does for #c-ignore.

Left for later

  • citry check does not report the refusals above. They show at the
    first render. With a :title on a v-pre element that holds Citry
    values, citry check reports an unrelated error instead.
  • v-pre, Markup, <c-raw> and #c-ignore inside a slot fill fail
    with "prepared opaque HTML values do not match definition declarations"
    when the receiving component's <c-slot /> sits inside a <c-element>.
    <c-i18n c-client="True"> is built that way. The bug is older than this
    change: Markup, <c-raw> and #c-ignore fail the same way on main.
    Its fix is a separate pull request.
  • v-pre on <c-element> itself fails with "prepared dynamic
    <c-element> does not support ... v-pre", as on main.

Tests

The new tests are in test_vue_hydration_regions.py. Most rendering
tests check the server HTML and that the page hydrates with no declines.
The SVG test checks the HTML only, because Citry does not hydrate SVG yet,
and the left-to-Vue test checks the compiled template instead.

  • test_citry_values_inside_v_pre_are_written_as_the_server_renders_them
    covers:
    • {{ }} values, a c-title binding, <c-if> and <c-for> inside;
    • a kept :x attribute inside;
    • c-title on the v-pre element and on a void one;
    • <textarea v-pre>;
    • a component whose root holds v-pre;
    • whitespace;
    • a value containing </script>;
    • <pre v-pre> with a leading newline, and a value that starts with
      \r\n;
    • <table v-pre>, and a <td v-pre> inside it;
    • <c-element> with a :x attribute, and <c-js />.
  • test_a_simple_components_slot_content_inside_v_pre_is_written_with_it
  • test_v_pre_rows_from_c_for_stay_data renders one and three rows and
    checks that both use one compiled template.
  • test_v_pre_with_only_written_markup_is_left_to_vue checks that the
    compiled template keeps v-pre for a :title on the element, a table,
    and a <my-widget> tag.
  • test_v_pre_in_svg_compiles_contents_that_hold_no_vue_syntax covers
    <svg v-pre> and a v-pre element inside SVG.
  • test_v_pre_contents_stay_data_so_rows_share_one_compiled_template
    renders 20 keyed rows, and checks that there is one compile and that no
    value is in the template.
  • test_a_simple_component_inside_v_pre_renders_in_place
  • test_a_component_inside_v_pre_is_refused_with_its_name, inside a
    <div v-pre> and inside a <table v-pre>
  • test_v_pre_refuses_what_it_cannot_write_as_html pins the error type
    and message for:
    • a :title on the element;
    • a #c-ignore element inside;
    • an unbalanced Markup;
    • a <c-slot /> and <c-error-fallback> inside;
    • Vue syntax inside <table v-pre> and inside <svg v-pre>.

24 of the 29 cases fail on main. The other five pass on main too and
stay as guards: the three left-to-Vue cases, which keep main's output,
the <c-for> rows case and the unbalanced-Markup refusal.

Changelog: a Fixes line in CHANGELOG.md.

🤖 Generated with Claude Code

Vue does not compile anything inside an element with `v-pre`, but Citry
wrote its own values there as data bindings: a `{{ name }}` reached the
page as `{{ $citryPrepared.citryText0 }}`, and a `c-title` binding on or
inside the element failed to compile.

A `v-pre` element that holds only HTML and Vue syntax is still left to
Vue, with `v-pre` kept. Otherwise Citry handles `v-pre` itself. It
writes the element without `v-pre`, so the element's own `c-` bindings
and `#c-key` compile as on any element. It writes the contents as one
block of HTML that reaches the browser as data, as a `#c-ignore` block
does but not pinned, so Vue inserts the server's HTML without compiling
it, request values stay out of the compiled template, and every row
shares one definition. Authored Vue attributes inside the element stay
plain attributes, as `v-pre` keeps them, and `simple = True` and
transparent components are written in place. A child component, a
`<c-slot>` outlet, an Events or browser binding, or a `#c-ignore`
element inside is refused, and so is a Vue attribute on the `v-pre`
element itself.

Where a block of HTML cannot sit (table rows and sections, SVG and
MathML), Citry drops only the attribute and compiles the contents as
usual, refusing contents that hold Vue syntax. A text-only element such
as `<textarea>` drops the attribute and renders its text as usual. A
`<pre v-pre>` block drops the line break written straight after the
start tag, as the browser does.

The step that joins static template nodes keeps a `v-pre` element's
closing tag as its own node. The fast path in `leaf_program.py`, used for
templates with no child components, leaves such templates to the general
assembler.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit ae42138 into main Oct 25, 2026
13 of 26 checks passed
@JuroOravec
JuroOravec deleted the fix/vue-v-pre branch October 25, 2026 08:12
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, a {{ }} expression shows {{ $citryPrepared.citryText0 }} instead of its value

1 participant