Backtestsvuerun-20261001-022054#15081
SSR hydration warning: dynamic props on SVG elements are patched as properties instead of attributes
The merged fix was judged better than our patch.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches fix the root cause the same way. During hydration they derive the element's namespace ('svg' / 'mathml' / undefined) from `el.namespaceURI` and pass it to `patchProp` instead of `undefined`. `patchProp` then routes SVG props through `setAttribute`, as client rendering does. Patch A also passes the namespace on the `onClick`-only branch. That is harmless but does not matter for the reported bug, since event listeners ignore namespace.
The real difference is the tests. Patch A's test checks `viewBox` on a jsdom `<svg>`. jsdom does not appear to implement a getter-only `viewBox` IDL property on SVGSVGElement, so `shouldSetAsProp` would likely fall back to `setAttribute` even without the fix. The test would then pass before the change and gives little regression protection. Patch B's first test has the same jsdom limitation. Its second test, however, defines a getter-only `width` on a `<foreignObject>` inside an `<svg>`, reproducing the read-only IDL property behind the reported TypeError. Without the namespace fix, `patchProp` would try to set it as a DOM prop and fail, leaving the attribute at '24'. With the fix, the attribute becomes '48'. That test genuinely fails before and passes after. It also exercises nested SVG elements, not just the root `<svg>`, and runs with `__DEV__=false` to cover the production force-patch path.
Scope and craft are comparable. A's helper function is slightly tidier, and B inlines the computation inside the loop's guard branch. Neither matters much. B wins on stronger, more meaningful test coverage.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
2m 39s11 turns
Wall-clock time in the container
Full test suite
No new failures
3,613 passed · 6 skipped · 3,621 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
39vs 67 merged
Changed lines, ours vs merged
The issue
View on GitHubVersion
3.5.39
Reproduction link
Steps to reproduce
- Open the reproduction.
- Open the browser devtools Console.
- Observe the
[Vue warn]: Failed setting prop …error logged during hydration.
What is expected?
During hydration, dynamic props on SVG (and MathML) elements width, height, viewBox, etc. should be patched as attributes (via setAttribute) exactly as they are during normal client-side rendering. Hydration should be silent.
What is actually happening?
Since 3.5.39, dynamic props on SVG elements are patched as DOM properties during hydration, which throws for read-only SVG IDL properties:
[Vue warn]: Failed setting prop "viewBox" on <svg>: value 0 0 24 24 is invalid.
TypeError: Cannot set property viewBox of #<SVGSVGElement> which has only a getter
at patchDOMProp
at patchProp
at hydrateElement
at hydrateNode
at hydrateSubTree
at <App>
Nothing is visually broken but the console is flooded with warnings.
We ran across this issue in a Nuxt app but I believe the issue is coming from Vue core
<!-- generated by vue-issues. DO NOT REMOVE -->
The two patches
packages/runtime-core/__tests__/hydration.spec.tsindex 144473dd3..52adea554 100644@@ -2776,5 +2776,26 @@ describe('SSR hydration', () => { expect(el.getAttribute('id')).toBe('client') expect(el.getAttribute('value')).toBe('server') })++ test('patches dynamic props on SVG elements as attributes when hydrating', () => {+ const { container } = mountWithHydration(+ `<svg data-allow-mismatch="attribute" viewBox="0 0 10 10"></svg>`,+ () =>+ createVNode(+ 'svg',+ {+ 'data-allow-mismatch': 'attribute',+ viewBox: '0 0 24 24',+ },+ null,+ PatchFlags.PROPS,+ ['viewBox'],+ ),+ )+ const el = container.firstChild as Element++ expect(`Failed setting prop "viewBox" on <svg>`).not.toHaveBeenWarned()+ expect(el.getAttribute('viewBox')).toBe('0 0 24 24')+ }) }) })packages/runtime-core/src/hydration.tsindex c315ab940..efb0e0e88 100644@@ -32,7 +32,11 @@ import { normalizeStyle, stringifyStyle, } from '@vue/shared'-import { type RendererInternals, needTransition } from './renderer'+import {+ type ElementNamespace,+ type RendererInternals,+ needTransition,+} from './renderer' import { setRef } from './rendererTemplateRef' import { type SuspenseBoundary,@@ -72,6 +76,13 @@ const isSVGContainer = (container: Element) => const isMathMLContainer = (container: Element) => container.namespaceURI!.includes('MathML') +const getElementNamespace = (el: Element): ElementNamespace =>+ el.namespaceURI!.includes('svg')+ ? 'svg'+ : el.namespaceURI!.includes('MathML')+ ? 'mathml'+ : undefined+ const getContainerType = ( container: Element | ShadowRoot, ): 'svg' | 'mathml' | undefined => {@@ -491,6 +502,7 @@ export function createHydrationFunctions( // props if (props) {+ const namespace = getElementNamespace(el) if ( __DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ ||@@ -520,7 +532,7 @@ export function createHydrationFunctions( (isCustomElement && !isReservedProp(key)) || (dynamicProps && dynamicProps.includes(key)) ) {- patchProp(el, key, null, props[key], undefined, parentComponent)+ patchProp(el, key, null, props[key], namespace, parentComponent) } } } else if (props.onClick) {@@ -531,7 +543,7 @@ export function createHydrationFunctions( 'onClick', null, props.onClick,- undefined,+ namespace, parentComponent, ) } else if (patchFlag & PatchFlags.STYLE && isReactive(props.style)) {
packages/runtime-core/__tests__/hydration.spec.tsindex 144473dd3..df0114065 100644@@ -2755,6 +2755,66 @@ describe('SSR hydration', () => { } }) + test('force patch svg dynamic props with correct namespace when hydrating', () => {+ __DEV__ = false+ try {+ const { container } = mountWithHydration(+ `<svg width="24" height="24" viewBox="0 0 24 24"></svg>`,+ () =>+ createElementVNode(+ 'svg',+ { width: 48, height: 48, viewBox: '0 0 48 48' },+ null,+ PatchFlags.PROPS,+ ['width', 'height', 'viewBox'],+ ),+ )+ const el = container.firstChild as Element+ expect(el.namespaceURI).toContain('svg')+ expect(el.getAttribute('width')).toBe('48')+ expect(el.getAttribute('height')).toBe('48')+ expect(el.getAttribute('viewBox')).toBe('0 0 48 48')+ } finally {+ __DEV__ = true+ }+ })++ test('force patch foreignObject dynamic props with correct namespace when hydrating', () => {+ __DEV__ = false+ try {+ const container = document.createElement('div')+ container.innerHTML =+ '<svg><foreignObject width="24"></foreignObject></svg>'+ const el = container.querySelector('foreignObject')!+ expect(el.namespaceURI).toContain('svg')+ // jsdom doesn't implement SVGForeignObjectElement.width.+ Object.defineProperty(el, 'width', {+ configurable: true,+ get: () => 24,+ })++ createSSRApp({+ render: () => (+ openBlock(),+ createElementBlock('svg', null, [+ (openBlock(),+ createElementBlock(+ 'foreignObject',+ { width: 48 },+ null,+ PatchFlags.PROPS,+ ['width'],+ )),+ ])+ ),+ }).mount(container)++ expect(el.getAttribute('width')).toBe('48')+ } finally {+ __DEV__ = true+ }+ })+ test('only patches declared dynamic props when hydrating', () => { const { container } = mountWithHydration( `<div data-allow-mismatch="attribute" id="server" value="server"></div>`,packages/runtime-core/src/hydration.tsindex c315ab940..405a5db93 100644@@ -500,6 +500,11 @@ export function createHydrationFunctions( patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION) ) { const isCustomElement = el.tagName.includes('-')+ const namespace = el.namespaceURI!.includes('svg')+ ? 'svg'+ : el.namespaceURI!.includes('MathML')+ ? 'mathml'+ : undefined for (const key in props) { // check hydration mismatch if (@@ -520,7 +525,7 @@ export function createHydrationFunctions( (isCustomElement && !isReservedProp(key)) || (dynamicProps && dynamicProps.includes(key)) ) {- patchProp(el, key, null, props[key], undefined, parentComponent)+ patchProp(el, key, null, props[key], namespace, parentComponent) } } } else if (props.onClick) {
What the agent reported
I fixed it: during hydration, dynamic props on SVG elements are now set as attributes again, so the Failed setting prop "viewBox" on <svg> warning no longer appears. The changes are uncommitted in the working tree.
What was wrong: the hydration code always passed undefined instead of the element's namespace when it applied dynamic props. The DOM renderer therefore treated an <svg> like a plain HTML element and tried to write viewBox as a property. That property is read-only on SVG elements, hence the warning. The problem appeared when hydration started force-patching dynamic props (commit 024cf06da, #9033).
What I changed (packages/runtime-core/src/hydration.ts):
- A new helper,
getElementNamespace(el), returns'svg','mathml'orundefinedbased on the element's own namespace. It uses the element itself so that<foreignObject>counts as SVG, which is how normal client rendering treats it. - Both places in
hydrateElementthat applied props now pass this namespace instead ofundefined. One is the main props loop; the other is the shortcut for click listeners.
Test evidence:
- I added a regression test in
packages/runtime-core/__tests__/hydration.spec.ts: "patches dynamic props on SVG elements as attributes when hydrating". The server HTML has<svg viewBox="0 0 10 10">and the client rendersviewBox: '0 0 24 24'as a dynamic prop. The test checks that the warning is not logged and that the attribute ends up as'0 0 24 24'. - Before the fix this test failed with
expected "Failed setting prop "viewBox" on <svg>" not to have been warned. The final reviewer suspected the test environment (jsdom) might not reproduce the bug, but this pre-fix failure shows it does. After the fix it passes. - The full hydration spec passes (113 tests). Running hydration together with the runtime-dom and server-renderer tests gives 650 passed and 2 failed. The 2 failures are GC tests in
ssrRender.spec.ts("render error leak"), and they fail the same way with my changes stashed, so they were already failing.
Requirements:
- Dynamic SVG props are patched with
setAttributeduring hydration, like client rendering: done; covered by the new test. - Hydration is silent, with no "Failed setting prop" warning: done; the new test asserts the warning is not logged.
- The
viewBoxcase from the report: this is the exact scenario the test covers. - The same for
width,height, etc.: these go through the same code path asviewBox, so the fix covers them. I didn't add a separate test for them. - The same for MathML: the namespace is now passed as
'mathml', which matches client rendering. The DOM renderer's attribute-vs-property choice doesn't change on'mathml', so nothing behaves differently in practice. There is no dedicated test.
The reviewer also found no unrelated changes. One side effect: class on SVG elements is now written with setAttribute during hydration instead of className, which also matches client rendering.