Backtestsvuerun-20261003-231210#15081
SSR hydration warning: dynamic props on SVG elements are patched as properties instead of attributes
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make the same core fix at the root cause. In the hydration props loop, each derives the element's own namespace ('svg' / 'mathml') from `el.namespaceURI` and passes it to `patchProp` instead of `undefined`. That makes runtime-dom's `shouldSetAsProp` take the SVG path and use `setAttribute`. Both correctly use the element's own namespace rather than `getContainerType`, so `<foreignObject>` itself is still treated as SVG.
Correctness differences are small:
- Patch A uses a non-null assertion on `namespaceURI`. This is safe in practice but less defensive.
- Patch B wraps the logic in a named helper that handles null, with a comment explaining why it differs from `getContainerType`.
- Patch B also applies the namespace to the `onClick` fast path, a minor consistency improvement.
Tests:
- Patch A's first SVG test likely does not fail before the fix. jsdom's SVGSVGElement doesn't expose width/height/viewBox as properties, so `key in el` is false and the attribute path is taken anyway.
- Only Patch A's foreignObject test, which installs a getter-only `width`, truly exercises the bug.
- Patch A also toggles `__DEV__` off to sidestep mismatch warnings, which is somewhat hacky.
- Patch B mimics browser behavior by installing getter-only `viewBox` on `<svg>` and `width` on `<foreignObject>`. It uses `data-allow-mismatch` instead of disabling `__DEV__`, and asserts both the attribute values and the absence of the 'Failed setting prop' warning, which is the issue's exact symptom.
- Patch B adds a MathML case too, though that one may not fail pre-fix in jsdom.
Overall, Patch B's tests reproduce the reported failure more faithfully and its code is slightly cleaner, so B is the better patch.
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
5m 58s
Wall-clock time in the container
Full test suite
No new failures
3,614 passed · 6 skipped · 3,622 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
74vs 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..2d4e629fc 100644@@ -2776,5 +2776,63 @@ describe('SSR hydration', () => { expect(el.getAttribute('id')).toBe('client') expect(el.getAttribute('value')).toBe('server') })++ test('patches dynamic props on svg elements as attributes', () => {+ const container = document.createElement('div')+ container.innerHTML =+ `<svg data-allow-mismatch="attribute" viewBox="0 0 10 10">` ++ `<foreignObject data-allow-mismatch="attribute" width="10"></foreignObject>` ++ `</svg>`+ const svg = container.firstChild as Element+ const fo = svg.firstChild as Element+ // mimic browsers, where these SVG IDL properties only have getters+ Object.defineProperty(svg, 'viewBox', { get: () => ({}) })+ Object.defineProperty(fo, 'width', { get: () => ({}) })++ createSSRApp({+ render: () => (+ openBlock(),+ createElementBlock(+ 'svg',+ { 'data-allow-mismatch': 'attribute', viewBox: '0 0 24 24' },+ [+ createElementVNode(+ 'foreignObject',+ { 'data-allow-mismatch': 'attribute', width: '24' },+ null,+ PatchFlags.PROPS,+ ['width'],+ ),+ ],+ PatchFlags.PROPS,+ ['viewBox'],+ )+ ),+ }).mount(container)++ expect(svg.getAttribute('viewBox')).toBe('0 0 24 24')+ expect(fo.getAttribute('width')).toBe('24')+ expect(`Failed setting prop`).not.toHaveBeenWarned()+ })++ test('patches dynamic props on MathML elements as attributes', () => {+ const container = document.createElement('div')+ container.innerHTML = `<math data-allow-mismatch="attribute" display="inline"></math>`+ const math = container.firstChild as Element+ expect(math.namespaceURI).toContain('MathML')++ createSSRApp({+ render: () =>+ createVNode(+ 'math',+ { 'data-allow-mismatch': 'attribute', display: 'block' },+ null,+ PatchFlags.PROPS,+ ['display'],+ ),+ }).mount(container)++ expect(math.getAttribute('display')).toBe('block')+ }) }) })packages/runtime-core/src/hydration.tsindex c315ab940..10d2da62d 100644@@ -81,6 +81,17 @@ const getContainerType = ( return undefined } +// namespace of the element itself (unlike getContainerType, <foreignObject>+// is still an SVG element even though its children are HTML)+const getElementNamespace = (el: Element): 'svg' | 'mathml' | undefined => {+ const ns = el.namespaceURI+ if (ns) {+ if (ns.includes('svg')) return 'svg'+ if (ns.includes('MathML')) return 'mathml'+ }+ return undefined+}+ export const isComment = (node: Node): node is Comment => node.nodeType === DOMNodeTypes.COMMENT @@ -500,6 +511,7 @@ export function createHydrationFunctions( patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION) ) { const isCustomElement = el.tagName.includes('-')+ const namespace = getElementNamespace(el) for (const key in props) { // check hydration mismatch if (@@ -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,+ getElementNamespace(el), 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) {