Backtestsvuerun-20261007-145226#15081

Issue #15081 Merged fix PR #15082 Run 7 Oct 2026 · run-20261007-145226 vuejs/core

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

Better

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 hydration they derive the element's own namespace from `el.namespaceURI` and pass it to `patchProp` instead of `undefined`. SVG and MathML dynamic props then go through the SVG-aware `shouldSetAsProp` logic and are set with `setAttribute`. Both correctly treat `<foreignObject>` as an SVG-namespace element; using `getContainerType` would have gotten this wrong.

Correctness is effectively equal. Patch A extracts a small, documented helper, `getElementNamespace`, that guards against a null `namespaceURI`. Patch B uses non-null assertions inline; this is safe in practice but less defensive. Patch A also passes the namespace on the `onClick`-only path. That change is harmless and neutral.

Tests: Patch A puts a getter-only `viewBox` on `SVGElement.prototype` to simulate the read-only IDL property. Without the fix, the `key in el` check would route to `patchDOMProp`, which would throw and warn. So the test asserts the exact symptom from the issue (no 'Failed setting prop' warning, attribute updated) and covers both `<svg>` and `<foreignObject>`.

Patch B's first test likely passes even without the fix, because jsdom's SVGSVGElement does not expose `width`/`height`/`viewBox` as properties, so they already fall through to `setAttribute`. That makes it weak. Its second test, an instance getter on `foreignObject.width`, is a valid regression test. Its toggling of `__DEV__` is a less clean way to avoid the warning path.

Overall, Patch A has the more targeted test of the reported symptom and slightly cleaner, safer code.

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 50s

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

52vs 67 merged

Changed lines, ours vs merged

Version

3.5.39

Reproduction link

stackblitz.com

Steps to reproduce

  1. Open the reproduction.
  2. Open the browser devtools Console.
  3. 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

Our patch+50 −2
packages/runtime-core/__tests__/hydration.spec.tsindex 144473dd3..f50f69105 100644@@ -2776,5 +2776,42 @@ 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', () => {+      // simulate read-only SVG IDL properties (e.g. SVGSVGElement.viewBox)+      Object.defineProperty(window.SVGElement.prototype, 'viewBox', {+        get: () => null,+        configurable: true,+      })+      try {+        const { container } = mountWithHydration(+          `<svg data-allow-mismatch="attribute" viewBox="0 0 10 10"><foreignObject data-allow-mismatch="attribute" viewBox="0 0 10 10"></foreignObject></svg>`,+          () =>+            createVNode(+              'svg',+              { 'data-allow-mismatch': 'attribute', viewBox: '0 0 24 24' },+              [+                createVNode(+                  'foreignObject',+                  { 'data-allow-mismatch': 'attribute', viewBox: '0 0 24 24' },+                  null,+                  PatchFlags.PROPS,+                  ['viewBox'],+                ),+              ],+              PatchFlags.PROPS,+              ['viewBox'],+            ),+        )+        const svg = container.firstChild as Element+        expect(svg.getAttribute('viewBox')).toBe('0 0 24 24')+        expect(svg.firstElementChild!.getAttribute('viewBox')).toBe(+          '0 0 24 24',+        )+        expect(`Failed setting prop`).not.toHaveBeenWarned()+      } finally {+        delete (window.SVGElement.prototype as any).viewBox+      }+    })   }) })packages/runtime-core/src/hydration.tsindex c315ab940..7fa20949f 100644@@ -81,6 +81,16 @@ const getContainerType = (   return undefined } +// namespace of the element itself (unlike getContainerType, a <foreignObject>+// element is still in the svg namespace - only its children are not)+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,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 +531,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 +542,7 @@ export function createHydrationFunctions(             'onClick',             null,             props.onClick,-            undefined,+            getElementNamespace(el),             parentComponent,           )         } else if (patchFlag & PatchFlags.STYLE && isReactive(props.style)) { 
Merged fix · PR #15082+66 −1
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) {