You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(compiler-core): honor HTML integration points for RCDATA/RAWTEXT - #16414
The tokenizer only recognizes <textarea>, <title>, <script> and <style> as RCDATA/RAWTEXT when inXML is false. The parser sets inXML when entering <svg>/<math> but never clears it at HTML integration points (foreignObject, desc, title, mtext, annotation-xml encoding="text/html"), even though getNamespace already assigns their children the HTML namespace.
As a result, <svg><foreignObject><textarea><b>x</b></textarea></foreignObject></svg> compiles to a real <b> element on the client and unescaped markup in SSR, while browsers parse the textarea content as text. SSR and hydration therefore disagree for these templates.
What changed
endOpenTag / onCloseTag now compute the tokenizer content mode from the element's own getNamespace resolution: HTML integration points switch back to HTML mode, and closing back into SVG/MathML restores XML mode.
Added compiler-dom parse tests for foreignObject textarea/title, math mtext, annotation-xml, plus plain HTML and root-namespace SVG controls.
Added compiler-ssr compiled-string assertions for the escaped output.
Plain HTML, root-namespace SVG (<svg><script> stays markup), <svg><style>, direct <svg><textarea>, and annotation-xml without encoding remain byte-identical.
Tests
New tests fail on the base (5 failed / 82 passed) and pass at head (87/87).
compiler-core/dom/ssr: 48 files / 989 tests pass.
Full unit suite: 4188 passed, 6 skipped.
pnpm typecheck and pnpm lint pass.
Summary by CodeRabbit
Bug Fixes
Fixed parsing of <textarea> content inside SVG and MathML integration points so markup is treated as text rather than parsed as elements.
Fixed <title> content inside SVG foreignObject to be treated as text.
Fixed server-rendered <textarea> content in SVG foreignObject to escape markup correctly.
Confirmed plain HTML <textarea> parsing and SVG-root <script> parsing remain unchanged.
No actionable comments were generated in the recent review.
Walkthrough
The parser now determines XML mode from the current parent element’s child-content namespace. Added tests cover HTML integration-point parsing, existing HTML and SVG parsing behavior, and SSR escaping of textarea content.
Changes: Content namespace handling
Layer / File(s)
Summary
Child-content namespace XML mode and validation packages/compiler-core/src/parser.ts, packages/compiler-dom/__tests__/parse.spec.ts, packages/compiler-ssr/__tests__/ssrElement.spec.ts
Opening and closing tags recalculate XML mode from the current parent’s child-content namespace. Parser tests cover textarea and title content at HTML integration points, plain HTML textarea behavior, and SVG script parsing. The SSR test checks HTML escaping of textarea content inside foreignObject.
This change makes the compiler parse textarea and title content inside SVG and MathML HTML integration points the way browsers do, which should reduce SSR and hydration mismatches. No actionable merge risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the compiler-core fix for RCDATA/RAWTEXT handling at HTML integration points. The changeset updates endOpenTag and onCloseTag in parser.ts to set tokenizer.inXML from the resolved chil…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the compiler-core fix for RCDATA/RAWTEXT handling at HTML integration points. The changeset updates endOpenTag and onCloseTag in parser.ts to set tokenizer.inXML from the resolved child-content namespace. The added tests cover textarea and title inside foreignObject, mtext, and annotation-xml, and the SSR test covers escaped textarea output. The title matches the main change and is specific, with a conventional commit prefix.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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
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.
Why
The tokenizer only recognizes
<textarea>,<title>,<script>and<style>as RCDATA/RAWTEXT wheninXMLis false. The parser setsinXMLwhen entering<svg>/<math>but never clears it at HTML integration points (foreignObject,desc,title,mtext,annotation-xml encoding="text/html"), even thoughgetNamespacealready assigns their children the HTML namespace.As a result,
<svg><foreignObject><textarea><b>x</b></textarea></foreignObject></svg>compiles to a real<b>element on the client and unescaped markup in SSR, while browsers parse the textarea content as text. SSR and hydration therefore disagree for these templates.What changed
endOpenTag/onCloseTagnow compute the tokenizer content mode from the element's owngetNamespaceresolution: HTML integration points switch back to HTML mode, and closing back into SVG/MathML restores XML mode.foreignObjecttextarea/title, mathmtext,annotation-xml, plus plain HTML and root-namespace SVG controls.Plain HTML, root-namespace SVG (
<svg><script>stays markup),<svg><style>, direct<svg><textarea>, andannotation-xmlwithoutencodingremain byte-identical.Tests
pnpm typecheckandpnpm lintpass.Summary by CodeRabbit
<textarea>content inside SVG and MathML integration points so markup is treated as text rather than parsed as elements.<title>content inside SVGforeignObjectto be treated as text.<textarea>content in SVGforeignObjectto escape markup correctly.<textarea>parsing and SVG-root<script>parsing remain unchanged.