Skip to content

fix(compiler-core): honor HTML integration points for RCDATA/RAWTEXT - #16414

Open
BlueX888 wants to merge 1 commit into
vuejs:mainfrom
BlueX888:contrib/foreign-content-rcdata
Open

BlueX888 wants to merge 1 commit into
vuejs:mainfrom
BlueX888:contrib/foreign-content-rcdata

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

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.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: yyx990803

Merge Risk: Minimal · up to 1e434

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7f9ffd5b-89e3-43cd-ace9-562c177a51d2
Commits

Reviewing files that changed from the base of the PR and between 44234e8 and 1e434b7.

Files selected for processing: 3

  • packages/compiler-core/src/parser.ts
  • packages/compiler-dom/__tests__/parse.spec.ts
  • packages/compiler-ssr/__tests__/ssrElement.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@16414
npm i https://pkg.pr.new/@vue/compiler-core@16414
yarn add https://pkg.pr.new/@vue/compiler-core@16414.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@16414
npm i https://pkg.pr.new/@vue/compiler-dom@16414
yarn add https://pkg.pr.new/@vue/compiler-dom@16414.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@16414
npm i https://pkg.pr.new/@vue/compiler-sfc@16414
yarn add https://pkg.pr.new/@vue/compiler-sfc@16414.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@16414
npm i https://pkg.pr.new/@vue/compiler-ssr@16414
yarn add https://pkg.pr.new/@vue/compiler-ssr@16414.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@16414
npm i https://pkg.pr.new/@vue/reactivity@16414
yarn add https://pkg.pr.new/@vue/reactivity@16414.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@16414
npm i https://pkg.pr.new/@vue/runtime-core@16414
yarn add https://pkg.pr.new/@vue/runtime-core@16414.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@16414
npm i https://pkg.pr.new/@vue/runtime-dom@16414
yarn add https://pkg.pr.new/@vue/runtime-dom@16414.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@16414
npm i https://pkg.pr.new/@vue/server-renderer@16414
yarn add https://pkg.pr.new/@vue/server-renderer@16414.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@16414
npm i https://pkg.pr.new/@vue/shared@16414
yarn add https://pkg.pr.new/@vue/shared@16414.tgz

vue

pnpm add https://pkg.pr.new/vue@16414
npm i https://pkg.pr.new/vue@16414
yarn add https://pkg.pr.new/vue@16414.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@16414
npm i https://pkg.pr.new/@vue/compat@16414
yarn add https://pkg.pr.new/@vue/compat@16414.tgz

commit: 1e434b7

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 115 kB 43.1 kB 38.6 kB
vue.global.prod.js 174 kB (+22 B) 63.5 kB (-1 B) 56.4 kB (+15 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 52.9 kB 20.4 kB 18.7 kB
createApp 61.1 kB 23.5 kB 21.5 kB
createSSRApp 65.9 kB 25.5 kB 23.2 kB
defineCustomElement 67.4 kB 25.4 kB 23.2 kB
overall 77.2 kB 29.3 kB 26.6 kB

This branch has not been deployed

No deployments
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.

1 participant