Backtestsvuerun-20261002-115633#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 A = our agent, Patch B = the merged fix.
Both patches fix the root cause the same way. During forced hydration patching they pass the element's own namespace ('svg' or 'mathml', taken from el.namespaceURI) to patchProp instead of undefined. As a result, shouldSetAsProp and patchAttr treat SVG props as attributes, just as client mount does. Both use the element's own namespace rather than the container type, so both handle <foreignObject> correctly. The differences are in robustness and tests. On robustness, Patch A's helper guards against a null namespaceURI, while Patch B uses non-null assertions. Patch A also passes the namespace in the onClick branch, which is harmless and consistent. On tests, Patch A's first test mimics a browser's getter-only viewBox, so before the fix the prop path throws and warns; it fails pre-fix and passes post-fix. Its xlink:href test also shows a real behavioral difference: setAttributeNS is used only when isSVG is true. Patch B's foreignObject test is a valid regression test. However, its first SVG test likely passes even without the fix in jsdom, because jsdom doesn't expose width/viewBox as IDL properties on SVGSVGElement. Patch B also toggles __DEV__ off, which obscures what the tests check. Overall the fixes are near-equivalent, and Patch A has slightly more defensive code and more meaningful tests.
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
7m
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
61vs 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..fdf7cb8d3 100644@@ -2776,5 +2776,49 @@ describe('SSR hydration', () => { expect(el.getAttribute('id')).toBe('client') expect(el.getAttribute('value')).toBe('server') })++ // #15081+ test('patch dynamic props on SVG elements as attributes', () => {+ const container = document.createElement('div')+ container.innerHTML = `<svg viewBox="0 0 24 24"></svg>`+ const svg = container.firstChild as SVGSVGElement+ // mimic browsers, where viewBox is a getter-only IDL property+ Object.defineProperty(svg, 'viewBox', {+ get: () => ({}),+ configurable: true,+ })+ createSSRApp({+ render: () =>+ createVNode(+ 'svg',+ { viewBox: '0 0 24 24' },+ null,+ PatchFlags.PROPS,+ ['viewBox'],+ ),+ }).mount(container)++ expect(svg.getAttribute('viewBox')).toBe('0 0 24 24')+ expect(`Failed setting prop "viewBox"`).not.toHaveBeenWarned()+ })++ test('patch dynamic xlink props on SVG elements with namespace', () => {+ const xlinkNS = 'http://www.w3.org/1999/xlink'+ const { container } = mountWithHydration(+ `<svg><use data-allow-mismatch="attribute"></use></svg>`,+ () =>+ h('svg', [+ createVNode(+ 'use',+ { 'data-allow-mismatch': 'attribute', 'xlink:href': '#client' },+ null,+ PatchFlags.PROPS,+ ['xlink:href'],+ ),+ ]),+ )+ const use = container.querySelector('use')!+ expect(use.getAttributeNS(xlinkNS, 'href')).toBe('#client')+ }) }) })packages/runtime-core/src/hydration.tsindex c315ab940..7236c8973 100644@@ -81,6 +81,16 @@ const getContainerType = ( return undefined } +// namespace of the element itself (unlike getContainerType, which resolves+// the namespace of a container's children and so excludes <foreignObject>)+const getElementNamespace = (el: Element): 'svg' | 'mathml' | undefined => {+ const ns = el.namespaceURI+ if (!ns) return undefined+ 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 +510,9 @@ export function createHydrationFunctions( patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION) ) { const isCustomElement = el.tagName.includes('-')+ // #15081 SVG/MathML props must be patched with the element's+ // namespace so they are set as attributes, same as client mount+ const namespace = getElementNamespace(el) for (const key in props) { // check hydration mismatch if (@@ -520,7 +533,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 +544,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) {