Backtestsvuerun-20261021-133314#15081

Issue #15081 Merged fix PR #15082 Run 21 Oct 2026 · run-20261021-133314 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 identically: they derive the element's namespace from `el.namespaceURI` and pass it to `patchProp` in the dynamic-props hydration branch, so runtime-dom's `shouldSetAsProp` routes SVG/MathML props to `setAttribute`. The independent tests confirm both resolve every scenario. The differences are in tests and craft. Patch A's tests emulate the browser's read-only IDL getters (viewBox, r, foreignObject width) and assert that no 'Failed setting prop' warning and no mismatch warning is emitted while the attribute value is preserved; this directly mirrors the issue's symptom and would fail on base. Patch B sets `__DEV__ = false` in both tests, which suppresses the very warning the issue is about and makes the tests rely on attribute values instead; its first test also does not define a read-only property, so on jsdom (where `width`/`viewBox` are not on the element) the key-in-el check already falls through to setAttribute and the test likely passes on base, making it weak evidence. Only B's second test (with the defined getter) reliably fails before the fix. On craft, A factors the namespace detection into a small documented helper that distinguishes element namespace from `getContainerType`'s foreignObject handling, and avoids B's non-null assertions on `namespaceURI`. A's additional use of the helper in the `onClick` branch is harmless (events ignore namespace) and neutral. Overall A is the better-tested, cleaner fix.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

4m 45s

Wall-clock time in the container

Full test suite

No new failures

1,729 passed · 1 skipped · 1,732 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

86vs 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+84 −2
packages/runtime-core/__tests__/hydration.spec.tsindex 144473dd3..d7fe49839 100644@@ -2755,6 +2755,76 @@ describe('SSR hydration', () => {       }     }) +    // browsers expose read-only IDL properties (e.g. SVGSVGElement.viewBox)+    // that throw when assigned, emulate that since jsdom may not have them+    const defineReadonlyProp = (el: Element, key: string) => {+      Object.defineProperty(el, key, {+        configurable: true,+        get() {+          return 'readonly'+        },+      })+    }++    test('patches dynamic props on SVG elements as attributes', () => {+      const container = document.createElement('div')+      container.innerHTML = `<svg viewBox="0 0 24 24"><circle r="5"></circle></svg>`+      const svg = container.firstChild as Element+      const circle = svg.firstChild as Element+      defineReadonlyProp(svg, 'viewBox')+      defineReadonlyProp(circle, 'r')++      const viewBox = '0 0 24 24'+      const r = '5'+      createSSRApp({+        render: () => (+          openBlock(),+          createElementBlock(+            'svg',+            { viewBox },+            [+              createElementVNode('circle', { r }, null, PatchFlags.PROPS, [+                'r',+              ]),+            ],+            PatchFlags.PROPS,+            ['viewBox'],+          )+        ),+      }).mount(container)++      expect(`Failed setting prop`).not.toHaveBeenWarned()+      expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()+      expect(svg.getAttribute('viewBox')).toBe(viewBox)+      expect(circle.getAttribute('r')).toBe(r)+    })++    test('patches dynamic props on SVG <foreignObject> as attributes', () => {+      const container = document.createElement('div')+      container.innerHTML = `<svg><foreignObject width="100"></foreignObject></svg>`+      const fo = container.firstChild!.firstChild as Element+      defineReadonlyProp(fo, 'width')++      createSSRApp({+        render: () => (+          openBlock(),+          createElementBlock('svg', null, [+            createElementVNode(+              'foreignObject',+              { width: '100' },+              null,+              PatchFlags.PROPS,+              ['width'],+            ),+          ])+        ),+      }).mount(container)++      expect(`Failed setting prop`).not.toHaveBeenWarned()+      expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()+      expect(fo.getAttribute('width')).toBe('100')+    })+     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..d6bf082e3 100644@@ -81,6 +81,17 @@ const getContainerType = (   return undefined } +// namespace of the element itself (unlike getContainerType, <foreignObject>+// is still an SVG element - only 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)) { 
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) {