Skip to content

fix: hydrate pages whose text holds a control character or noncharacter - #284

Merged
JuroOravec merged 1 commit into
mainfrom
fix/control-characters-in-page-text
Oct 23, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/control-characters-in-page-text

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Fixes #281

What was wrong

When a page hydrates, Citry checks that the browser will build the same
tree from the server's HTML as Vue expects. It first runs a quick check
on the tags it writes (the token check); when that cannot decide, it
parses the whole page (the full parse), with html5gum's tokenizer feeding
html5ever's tree builder. The full parse, and the check that a <c-raw>
block or a Markup value is complete HTML, gave up on every error the
tokenizer reported.

The HTML standard reports a control character (DEL, U+0001 to U+0008,
U+000B, U+000E to U+001F, U+0080 to U+009F) or a Unicode noncharacter
(such as U+FDD0 or U+FFFE) in the input as a parse error, but the browser
keeps the character where it was written. So:

  • a page whose text or attribute value held one of these characters was
    refused hydration with the reason browser-structure, and Vue built it
    again in the browser;
  • a complete <c-raw> block or Markup value holding one, inside an
    interactive component, failed the render with "is not a complete HTML
    fragment".

The fix

  • output_scanner.rs: the full parse and the complete-HTML check no
    longer fail on control-character-in-input-stream and
    noncharacter-in-input-stream. Every other tokenizer error still fails
    them: these checks accept only explicit, correctly nested markup, and
    these two are the only errors the server's escaped text and attribute
    values can hold (the server rejects NUL and carriage returns). html5gum
    never reports surrogate-in-input-stream for a Rust string.
  • output_scanner.rs: tokenizer errors are no longer passed to
    html5ever's tree builder. The browser's tree builder never receives
    them, but html5ever's counts an error as the token right after <pre>,
    <listing> or <textarea>, and html5gum reports a character's error
    before the text that holds it. With only the first change, the full
    parse would have kept the newline after <pre> that the browser drops,
    and accepted <pre>\na\x7fb</pre> written for the text "\na\x7fb".
    The random-tree test in hydration_nesting.rs found this once its
    texts included these characters.
  • server_render.rs: the writer no longer sends a page holding these
    characters to the full parse. The token check covers them, because the
    browser keeps them as written and they do not change where any tag ends
    up. The module docs and docs/design/vue_ssr_selected_tree_plan.md now
    say so.

Tests

  • Rust: text_the_full_parse_reports_is_left_to_it is renamed
    control_characters_and_noncharacters_are_written_as_they_are and now
    expects the written HTML; its helper checks that the token check and the
    full parse give the same answer. New cases in output_scanner.rs and
    hydration_structure.rs cover text, attribute values, comments, the
    newline after <pre>, <listing> and <textarea>, and a NUL that
    still fails. The random-tree test now generates text holding DEL and
    U+FDD0.
  • Python: three tests in test_vue_hydration_regions.py render pages with
    these characters in text, in an attribute value, in a <c-raw> block
    and in a Markup value, and check that they hydrate with the
    characters written as they are. Nine of these cases were run against
    main's native build, and all nine failed there.
  • The Vue render parity check compares those twelve pages with Vue's
    renderToString: 12 pages compared, 0 mismatches.
  • Separately, parse5 7.3.0 (the parser jsdom uses) keeps every one of
    these characters in text and attribute values, and drops the newline
    after <pre>, as the corrected parse does.
  • scripts/check.py --profile fast: PASSED.

Changelogs: one Fixes line in CHANGELOG.md, and one Fixed line in
packages/py/citry_core/CHANGELOG.md (v1.9.0, not yet released), because
html_transform.validate_html_fragment_boundary() and
browser_fragment_matches_nodes() are public and now accept this HTML.

Left for later:

  • The character references &#127;, &#x80; and &#xfdd0; in a
    <c-raw> block are still refused, while the literal characters pass.
    The server never writes them, and a reference such as &#x80; is
    remapped by the browser, so they need their own decision.
  • The parity script's Python HTML parser turns an invalid character
    reference such as &#127; into an empty string, where the browser keeps
    the code point. Both renderers write these characters as they are, so
    the comparison is right today.

🤖 Generated with Claude Code

The full parse that checks a page before it hydrates, and the check that a
<c-raw> block or Markup value is complete HTML, failed on every html5gum
tokenizer error. The HTML standard reports a control character (other than
whitespace and NUL) or a Unicode noncharacter in the input as a parse
error, but the browser keeps the character as written. Pages holding one
were refused hydration (`browser-structure`), and such a <c-raw> block in
an interactive component failed the render.

- output_scanner.rs: ignore control-character-in-input-stream and
  noncharacter-in-input-stream; every other error still fails both checks.
- output_scanner.rs: stop passing tokenizer errors to html5ever's tree
  builder. html5ever counts an error as the token after <pre>, <listing>
  or <textarea>, and html5gum reports a character's error before its
  text, so forwarding it kept a newline the browser drops (found by the
  random-tree test once its texts held these characters).
- server_render.rs: the token check now covers these characters, so the
  writer no longer sends such pages to the full parse.
- Tests in Rust and Python; the parity check compares the new pages with
  Vue's renderToString (0 mismatches). Changelog lines for citry and
  citry-core.

Fixes #281

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit d132178 into main Oct 23, 2026
33 checks passed
@JuroOravec
JuroOravec deleted the fix/control-characters-in-page-text branch October 23, 2026 19:26
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.

A page whose text holds DEL (U+007F) is not hydrated, which fails the Vue render parity check

1 participant