Skip to content

fix(hydration): preserve namespace when patching dynamic props - #15086

Closed
edison1105 wants to merge 1 commit into
mainfrom
edison/fix-15081-svg-hydration-namespace
Closed

edison1105 wants to merge 1 commit into
mainfrom
edison/fix-15081-svg-hydration-namespace

Conversation

@edison1105

@edison1105 edison1105 commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

close #15081

Summary by CodeRabbit

  • Bug Fixes
    • Improved server-rendered hydration for SVG elements.
    • Ensured SVG properties such as viewBox are correctly applied as attributes during hydration.
    • Prevented unnecessary hydration warnings for valid SVG attribute mismatches.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Hydration now derives SVG/MathML namespaces and passes them to patchProp, ensuring dynamic SVG attributes such as viewBox are patched correctly. A regression test verifies silent SVG hydration.

Changes

Hydration namespace handling

Layer / File(s) Summary
Namespace-aware prop hydration
packages/runtime-core/src/hydration.ts, packages/runtime-core/__tests__/hydration.spec.ts
hydrateElement passes the detected SVG or MathML namespace to hydrated prop patching, including the onClick path. A test verifies SVG viewBox hydration updates the attribute without a warning.

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

Possibly related PRs

  • vuejs/core#9083: Updates hydration handling for dynamically patched properties.
  • vuejs/core#14837: Adjusts SVG/MathML namespace handling during hydration mismatch recovery.
  • vuejs/core#15082: Adds related namespace-aware hydration changes and SVG regression tests.

Suggested labels: :hammer: p3-minor-bug, scope: ssr, scope:hydration

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main hydration namespace fix for dynamic prop patching.
Linked Issues check ✅ Passed The code preserves SVG/MathML namespaces during hydration, matching the issue's requirement to patch dynamic props as attributes without warnings.
Out of Scope Changes check ✅ Passed The changes are limited to the hydration fix and its regression test, with no unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/fix-15081-svg-hydration-namespace

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 107 kB (+83 B) 40.3 kB (+12 B) 36.2 kB (+18 B)
vue.global.prod.js 165 kB (+83 B) 60.4 kB (+11 B) 53.6 kB (-42 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 49 kB 19 kB 17.4 kB
createApp 57.1 kB 22.1 kB 20.2 kB
createSSRApp 61.7 kB (+83 B) 24 kB (+21 B) 21.8 kB (+7 B)
defineCustomElement 63.3 kB 24 kB 21.9 kB
overall 71.9 kB 27.5 kB 25.1 kB

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 5c95ec0

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/runtime-core/__tests__/hydration.spec.ts (1)

2763-2787: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the MathML half of the namespace contract.

This regression only exercises SVG, while the production change also introduces a 'mathml' namespace path. Add a dynamic MathML-property case, or confirm equivalent coverage elsewhere, so regressions in that path cannot pass unnoticed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-core/__tests__/hydration.spec.ts` around lines 2763 - 2787,
Extend the hydration coverage in the test around “patches dynamic props as
attributes on SVG elements” with an equivalent dynamic MathML element/property
case. Verify the MathML namespace path patches the changed property as an
attribute and emits no failed-property warning, matching the existing SVG
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/runtime-core/src/hydration.ts`:
- Around line 494-498: Update the downstream patching contract in patchProp to
recognize namespace === 'mathml' and route MathML properties through
setAttribute-based handling, while leaving the existing namespace === 'svg'
behavior unchanged. Add a regression test covering dynamic MathML property
hydration and verify it uses attribute patching rather than normal DOM-property
detection.

---

Nitpick comments:
In `@packages/runtime-core/__tests__/hydration.spec.ts`:
- Around line 2763-2787: Extend the hydration coverage in the test around
“patches dynamic props as attributes on SVG elements” with an equivalent dynamic
MathML element/property case. Verify the MathML namespace path patches the
changed property as an attribute and emits no failed-property warning, matching
the existing SVG assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e6a9408-2d17-4562-9e01-9c3247557b3c

📥 Commits

Reviewing files that changed from the base of the PR and between 9e03beb and 5c95ec0.

📒 Files selected for processing (2)
  • packages/runtime-core/__tests__/hydration.spec.ts
  • packages/runtime-core/src/hydration.ts

Comment on lines +494 to +498
const namespace = el.namespaceURI!.includes('svg')
? 'svg'
: el.namespaceURI!.includes('MathML')
? 'mathml'
: undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Ensure MathML is handled by the downstream attribute path.

This sets namespace to 'mathml', but packages/runtime-dom/src/patchProp.ts currently derives isSVG only for namespace === 'svg'. MathML hydration therefore still uses normal DOM-property detection instead of reliably patching dynamic props with setAttribute, leaving the MathML half of the stated fix unresolved.

Update the downstream patching contract to explicitly route MathML properties through attribute handling while preserving SVG-specific behavior, and add a MathML regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-core/src/hydration.ts` around lines 494 - 498, Update the
downstream patching contract in patchProp to recognize namespace === 'mathml'
and route MathML properties through setAttribute-based handling, while leaving
the existing namespace === 'svg' behavior unchanged. Add a regression test
covering dynamic MathML property hydration and verify it uses attribute patching
rather than normal DOM-property detection.

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.

SSR hydration warning: dynamic props on SVG elements are patched as properties instead of attributes

1 participant