Skip to content

Whitespace differs between Python-rendered HTML and Vue's render #152

Open

Description

@JuroOravec

(Opus 5.5)

What the reader sees

The same component shows different whitespace depending on how Citry sends the page. Vue's template compiler condenses whitespace; Citry's Python template rendering keeps the authored text exactly. Take this template:

<p>
  <a href="#">one</a>
  <a href="#">two</a>
</p>

Observed (attributes shortened) on the current development branch (citry-benchmark-design, 2026-09-28):

How the page is sent HTML for the paragraph Visible text
Hydrated (component has js, server writes Vue's render) <p><a>one</a><a>two</a></p> onetwo
Hydration declined, for example a custom on_dependencies hook (reason="custom-hooks") \n<p>\n <a>one</a>\n <a>two</a>\n</p>\n until Vue mounts, then Vue's version one two, then onetwo
Static output (component without js) same as the Python HTML above one two

Vue drops a whitespace-only text between two elements when it contains a newline, so the links touch. The Python HTML keeps the newline, which the browser shows as one space.

Other differences found in the same check:

  • <textarea>: Vue condenses the content ("\n t\n" becomes " t "), while the Python HTML keeps it. The field's initial value differs between static output and a Vue page.
  • <pre> on a hydrated page is written as a data-allow-mismatch="children" shell holding Python's HTML, and Vue builds its content in the browser. It hydrates correctly, but it is a shell only because of whitespace.

What is already consistent

  • Hydrated pages: the Rust server render programs run Vue's compiled render functions, so the server HTML and Vue's first render match exactly, whitespace included.
  • ssr=False and pages below ssr_element_threshold send an empty mount element, so there is nothing to flash.
  • Text produced in Python ({{ value }}) and <c-raw> / Markup HTML are written unchanged on every path. Vue does not condense values set through bindings either.
  • No whole-document whitespace pass runs per render any more. serialize.py, _vue/serialization.py and citry_html_transform contain no whitespace rewrite. One leftover: _vue/compiler.py still validates the compiler's authored_text_plan (the condense.whitespace / condense.drop-whitespace actions) and stores it on CompiledRender, but no code reads it. It runs once per compile, not per render.

So the remaining difference is between Vue's whitespace rules and Python's template rendering. It shows up in two places: a page Vue replaces when it mounts (visible text shift), and a component rendered without JS compared with the same component rendered by Vue.

Options the maintainer proposed

  1. A setting, on by default, that condenses whitespace the way Vue does when Citry renders a template in Python, so the output matches Vue. The setting can be turned off to keep authored whitespace. The Rust Vue compiler already reports which authored text Vue condenses or drops (authored_text_plan), so Python could apply the same actions at compile time, not per render.
  2. Require <c-raw> to print whitespace exactly as written, and condense everything else.
  3. Follow Vue's exceptions: keep whitespace inside <pre> (Vue also drops the first newline after <pre>), and keep <script> / <style> content as written (Vue templates do not render these tags). Note that Vue does condense <textarea>.

Options 2 and 3 can combine with option 1: option 1 decides the default, and 2 and 3 decide where authored whitespace survives.

Error modes to decide

  • Setting has an invalid value: a non-bool should raise TypeError when CitrySettings is created, like ssr.
  • Setting is off but the page hydrates: hydrated HTML comes from Vue's compiled render and is condensed anyway. Either the setting also switches Vue's compiler to whitespace: "preserve" (so both sides keep whitespace), or the docs state that the setting only affects Python-rendered output. A setting that only changes one side reintroduces the text shift.
  • CSS white-space: pre / pre-wrap on a normal element: the compiler cannot see CSS, so condensed text renders differently from the authored source. Vue has the same limit; the docs should say to use <pre> or <c-raw>.
  • Whitespace inside <c-raw> or a Markup value: stays exactly as written in every mode.
  • Text that spans a component boundary or a slot fill: the rule must give the same result whether Python or Vue renders the parent, or the declined-page flash remains for slots.

Acceptance

For each template in a small set (inline elements separated by newlines, <pre>, <textarea>, slots, <c-raw>), the static output, the declined-hydration server HTML, and Vue's browser render produce the same text nodes.

Activity

  1. added
    next-sprint
    on Oct 28, 2026
  2. added
    v0.9.0
    and removed
    next-sprint
    on Nov 14, 2026
  3. added a commit that references this issue on Nov 14, 2026
  4. added
    next-sprint
    and removed
    v0.9.0
    on Nov 14, 2026
  5. JuroOravec commented on Nov 14, 2026

    @JuroOravec
    MemberAuthor

    Moved to after 1.0.0 (label v1.1). The design needs a patched vize crate, compiler output changes and a citry-core release, and #624's decision 2 keeps exact whitespace outside the 1.0 stability promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions