Repository navigation
Description
What happens
When a page hydrates, the server writes the page's HTML for Vue to adopt,
so the browser does not build the page a second time. If the page's text
or an attribute value holds DEL (U+007F), the server refuses to write that
HTML: the page records the reason browser-structure ("the browser would
build a different tree from this HTML"), and Vue replaces the server's HTML
and builds the whole page again in the browser. The same happens for the
other control characters U+0001 to U+0008, U+000B, U+000E to U+001F and
U+0080 to U+009F, and for Unicode noncharacters such as U+FDD0 and U+FFFE.
The Vue render parity check (scripts/vue_render_parity/, the "vue render
parity" phase of scripts/check.py) renders every page the test suite
records with both Citry's Rust renderer and Vue's renderToString, and
compares the HTML. It counts every browser-structure refusal as a
failure, so the phase fails as soon as any test renders such a page. That
is how this showed up: a new test page with DEL in its text failed the
phase.
Both render paths behave the same (the Python path,
CITRY_NATIVE_RENDER=0, and the default path), because both hand the page
to the same Rust hydration renderer.
Reproduction
On main at 0305dfb, a page that hydrates:
from typing import Any
from citry import Citry, Component
from citry._vue.serialization import hydration_admission
def admission(text: str) -> Any:
engine = Citry(autodiscover=False)
class Page(Component):
citry = engine
def template_data(self, kwargs: Any, slots: Any) -> dict[str, Any]:
return {"text": text}
template = """
<!doctype html>
<html>
<head><title>Page</title></head>
<body><main><p>{{ text }}</p></main></body>
</html>
"""
js = """
$component({data() { return {count: 0}; }});
"""
rendered = Page().render()
rendered.serialize()
return hydration_admission(rendered)
for text in ["ab", "a\x7fb", "a\x01b", "a\x80b", "a\ufdd0b"]:
result = admission(text)
print(f"{ascii(text):12} hydrated={result.hydrated} reason={result.reason}")Output, the same with CITRY_NATIVE_RENDER=0 and with the default:
'ab' hydrated=True reason=None
'a\x7fb' hydrated=False reason=browser-structure
'a\x01b' hydrated=False reason=browser-structure
'a\x80b' hydrated=False reason=browser-structure
'a\ufdd0b' hydrated=False reason=browser-structure
The parity check on one recorded page, made by running the same page as a
pytest test with -p scripts.vue_render_parity.collect --vue-render-parity-corpus=DIR, then
scripts/vue_render_parity/check.py --reuse --corpus DIR (exit status 1,
other summary lines left out):
pages declined as a whole (mount in the browser): 1 {'browser-structure': 1}
pages compared: 0, shells inside them: 0
mismatches: 0, Vue errors: 0, parse-check failures: 1
FAIL no page was compared
The HTML Citry writes is correct
Vue's renderToString writes DEL as it is, <p>a\u007fb</p>, and so does
Citry's hydration writer: in text it escapes &, < and >, refuses CR
and NUL, and writes every other character as it is (escape_text,
crates/citry_vue_compiler/src/server_render.rs:3632).
The browser keeps the character. The HTML standard lists
control-character-in-input-stream and noncharacter-in-input-stream as
parse errors and says "such code points are parsed as-is and usually ...
make their way into the DOM". parse5 7.3.0, the standard-following parser
that jsdom uses, builds the same <p> with the text a\u007fb and reports
only that error. So neither the server's HTML writer nor the parity
script's Python parser is wrong: the page never reaches the comparison.
Cause
Citry's own check of the written HTML treats any tokenizer error as a
changed tree:
tokenizer_reports(server_render.rs:3606) marks these characters.
A text holding one (:2479) or an attribute value holding one
(:2903) sends the page past the quick token check, which reuses
parse results stored from earlier pages, to a full parse of the page
(html5gum's tokenizer feeding html5ever's tree builder).- The full parse,
parse_div_fragment_with_lexical_text
(crates/citry_html_transform/src/output_scanner.rs:449), gives up on
every error the tokenizer reports: theCallbackEvent::Errorarm
(:359) setstracker.valid = false, so the function returnsNone,
browser_fragment_matches_nodesreturnsfalse, and
server_render.rs:2183recordsbrowser-structure.
The repository disagrees with itself about this refusal. The Rust test
text_the_full_parse_reports_is_left_to_it (server_render.rs:4688)
expects it, and its comment says the browser keeps such text. The parity
check (scripts/vue_render_parity/check.py:569) treats every
browser-structure refusal as a renderer defect.
The same cause makes a <c-raw> block fail the render
The same error arm (output_scanner.rs:363) also rejects a <c-raw>
block, and there the render itself fails. In an interactive component, a
<c-raw> block whose HTML holds DEL (<c-raw><b>a\x7fb</b></c-raw> as a
Python string) raises on both render paths:
ValueError: The <c-raw> block at line 5, column 22 is not a complete HTML
fragment: '<b>a\x7fb</b>'. Inside an interactive component, Vue inserts
this HTML as one block, so every tag it opens must be closed inside it, ...
The block is complete. The error comes from
validate_html_fragment_boundary (output_scanner.rs:492), which
reject_cross_boundary_html
(packages/py/citry/citry/_vue/opaque_html.py:22) calls.
Fix direction
In output_scanner.rs, ignore the two tokenizer errors that leave the
tree and the text unchanged, ControlCharacterInInputStream and
NoncharacterInInputStream (html5gum 0.8.4, src/char_validator.rs:95
and :104), for both the lexical_text tracker and the boundary
tracker. Keep failing on every other error: a NUL, for example, does
change what the browser builds. Pages with these characters then hydrate
and reach the parity comparison, and the <c-raw> block renders. Update
text_the_full_parse_reports_is_left_to_it to expect the written HTML,
and add test pages with DEL in a text, an attribute value and a <c-raw>
block.
Once these pages reach the comparison, one more difference matters:
Python's html.parser turns the reference  into an empty string,
while the browser turns it into U+007F. Both sides write DEL as it is
today, so the comparison is right, but it would misread a page that wrote
DEL as a character reference.
Activity