Repository navigation
fix: render Citry values inside v-pre as HTML that Vue inserts - #348
Merged
Merged
Conversation
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
force-pushed
the
fix/vue-v-pre
branch
from
October 24, 2026 23:43
f6a6f97 to
9de24c0
Compare
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 #329
What was wrong
Inside an element with
v-pre, Citry's own template syntax reached thepage as internal names:
showed
{{ $citryPrepared.citryText0 }} and {{ $citryPrepared.citryText1 }}.A
c-title="name"binding, inside the element or on it, failed to compilewith
ELEMENT_ATTRS_BINDING_MISMATCH, and so did#c-keyon av-prerowof a loop.
Citry evaluates its
{{ }},c-bindings,<c-if>and<c-for>inPython, 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 aswritten.
The fix
Of the two options in the issue, I took the first: inside
v-pre, Citrywrites the values it already computed.
A
v-preelement that holds only HTML and Vue syntax is left to Vue,as on
main. Citry writes it withv-prekept, and Vue reads the elementand its contents as written (
_v_pre_left_to_vuein_vue/direct_capture.py).<c-js />,<c-css />and a transparentcomponent that holds only written markup count as written markup here.
A
<c-if>or<c-for>takes Citry's path, so rows and branches chosenat render time stay data.
Otherwise Citry handles
v-preitself:The element is written without
v-pre(_without_v_pre). Its ownc-bindings and#c-keythen compile as on any element. Citry refusesan authored Vue attribute such as
:titleon the element, which Vuewould write as a plain attribute under
v-pre, and says to move itinside. The tag itself compiles as it does on
main: Citry's Vuecompiler (vize) decides whether a tag such as
<my-widget>or<slot>is a component or a slot whether or not
v-preis set.The contents go out as one block of HTML that reaches the browser as
data. This is the path a
#c-ignoreblock takes, but the block is notpinned, so a later render replaces it with the new values. Vue inserts
the server's HTML without compiling it. Several things follow:
as
</script>is safe, and every row of a loop shares one compileddefinition.
Markupvalue is refused, as everywhere else.spaces into one under
v-pre; the server HTML keeps it, as a pagewithout Vue does.
<!--[-->and<!--]-->marker commentsinside the element. Code that reads the element's child nodes sees
them. CSS
:emptyignores comments.<pre>, but notafter 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-ignoreuses(
_ignored_contents_html). Authored Vue attributes stay plainattributes, as
v-prekeeps them. Asimple = Truecomponent and atransparent 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-ignoreelement, 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>,<thead>,<tbody>,<tfoot>,<tr>,<colgroup>), because the browser moves a block of HTML out ofthem;
<svg>,<math>and anything inside them, because the browsercannot 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 contentVue would compile. Compiling them would run what
v-prekeeps aswritten. A nested
v-preelement there gets its own block. The errorsuggests putting
v-preon a<td>or on an element that wraps thetable or the SVG.
Text-only elements (
<textarea v-pre>,<title v-pre>) follow the samerule: the attribute is dropped and their text renders as usual.
_vue/capture.py: the step that joins static template nodes keeps av-preelement'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 childcomponents leaves a template with
v-preto the general assembler, asit does for
#c-ignore.Left for later
citry checkdoes not report the refusals above. They show at thefirst render. With a
:titleon av-preelement that holds Citryvalues,
citry checkreports an unrelated error instead.v-pre,Markup,<c-raw>and#c-ignoreinside a slot fill failwith "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 thischange:
Markup,<c-raw>and#c-ignorefail the same way onmain.Its fix is a separate pull request.
v-preon<c-element>itself fails with "prepared dynamic<c-element>does not support ... v-pre", as onmain.Tests
The new tests are in
test_vue_hydration_regions.py. Most renderingtests 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_themcovers:
{{ }}values, ac-titlebinding,<c-if>and<c-for>inside;:xattribute inside;c-titleon thev-preelement and on a void one;<textarea v-pre>;v-pre;</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:xattribute, and<c-js />.test_a_simple_components_slot_content_inside_v_pre_is_written_with_ittest_v_pre_rows_from_c_for_stay_datarenders one and three rows andchecks that both use one compiled template.
test_v_pre_with_only_written_markup_is_left_to_vuechecks that thecompiled template keeps
v-prefor a:titleon the element, a table,and a
<my-widget>tag.test_v_pre_in_svg_compiles_contents_that_hold_no_vue_syntaxcovers<svg v-pre>and av-preelement inside SVG.test_v_pre_contents_stay_data_so_rows_share_one_compiled_templaterenders 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_placetest_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_htmlpins the error typeand message for:
:titleon the element;#c-ignoreelement inside;Markup;<c-slot />and<c-error-fallback>inside;<table v-pre>and inside<svg v-pre>.24 of the 29 cases fail on
main. The other five pass onmaintoo andstay as guards: the three left-to-Vue cases, which keep
main's output,the
<c-for>rows case and the unbalanced-Markuprefusal.Changelog: a Fixes line in
CHANGELOG.md.🤖 Generated with Claude Code