Repository navigation
fix: hydrate pages whose text holds a control character or noncharacter - #284
Merged
Merged
Conversation
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]>
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 #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
Markupvalue is complete HTML, gave up on every error thetokenizer 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:
refused hydration with the reason
browser-structure, and Vue built itagain in the browser;
<c-raw>block orMarkupvalue holding one, inside aninteractive component, failed the render with "is not a complete HTML
fragment".
The fix
output_scanner.rs: the full parse and the complete-HTML check nolonger fail on
control-character-in-input-streamandnoncharacter-in-input-stream. Every other tokenizer error still failsthem: 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-streamfor a Rust string.output_scanner.rs: tokenizer errors are no longer passed tohtml5ever'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 errorbefore 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.rsfound this once itstexts included these characters.
server_render.rs: the writer no longer sends a page holding thesecharacters 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.mdnowsay so.
Tests
text_the_full_parse_reports_is_left_to_itis renamedcontrol_characters_and_noncharacters_are_written_as_they_areand nowexpects the written HTML; its helper checks that the token check and the
full parse give the same answer. New cases in
output_scanner.rsandhydration_structure.rscover text, attribute values, comments, thenewline after
<pre>,<listing>and<textarea>, and a NUL thatstill fails. The random-tree test now generates text holding DEL and
U+FDD0.
test_vue_hydration_regions.pyrender pages withthese characters in text, in an attribute value, in a
<c-raw>blockand in a
Markupvalue, and check that they hydrate with thecharacters written as they are. Nine of these cases were run against
main's native build, and all nine failed there.renderToString: 12 pages compared, 0 mismatches.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 inpackages/py/citry_core/CHANGELOG.md(v1.9.0, not yet released), becausehtml_transform.validate_html_fragment_boundary()andbrowser_fragment_matches_nodes()are public and now accept this HTML.Left for later:
,€andin a<c-raw>block are still refused, while the literal characters pass.The server never writes them, and a reference such as
€isremapped by the browser, so they need their own decision.
reference such as
into an empty string, where the browser keepsthe code point. Both renderers write these characters as they are, so
the comparison is right today.
🤖 Generated with Claude Code