Backtestsvuerun-20261007-145226#5081

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

Throw an error on createVNode with using innerHTML and children at the same time

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

The issue is a render function that sets `innerHTML: undefined` together with children. It crashes, and the user wants to toggle between innerHTML and children dynamically, rendering whichever is provided.

Patch B only adds a dev-mode warning in createBaseVNode when a non-nullish innerHTML/textContent prop sits alongside children. It changes no runtime behavior. For the reported case (`innerHTML: undefined`) it explicitly emits nothing. It does nothing about the broken toggle: children mounted while innerHTML is set get overwritten and become detached, and switching back can leave stale or empty content. Its tests only assert warning messages, so they don't exercise the bug at all. B is a diagnostic, not a fix.

Patch A fixes the root cause by making client mount/patch semantics match SSR and hydration: when innerHTML/textContent is non-null, children are not mounted.
- mountElement skips children in that case.
- patchElement handles all transitions:
  - children → override: unmount old children and reset the new vnodes' mounted state.
  - override → children: clear the content and mount the new children fresh.
  - override → override: no-op.
  - It also guards TEXT patch flags.
- patchBlockChildren and unmount skip never-mounted vnodes reached through a parent block's dynamicChildren.
- traverseStaticChildren avoids inheriting els in that case.
- SSR now uses `!= null` instead of truthiness.

This is a larger and riskier change; for example, `isNeverMounted` relies on el/component being null. But it is coherent, and it is backed by thorough tests that would fail before the change:
- the exact issue reproduction
- text and array toggling, including component mount/unmount counts
- textContent toggling
- hydration with an override
- SSR edge cases
- a compiled template where a `:innerHTML` element sits inside a block with dynamic children

A addresses the requested behavior; B does not.

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

15m 28s

Wall-clock time in the container

Full test suite

No new failures

3,661 passed · 6 skipped · 3,667 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

374vs 81 merged

Changed lines, ours vs merged

Version

3.2.24

Reproduction link

codesandbox.io

Steps to reproduce

import { createApp, defineComponent, h } from "vue";

const App = defineComponent({
  setup() {
    return () => h("div", { innerHTML: undefined }, "a");
  }
});

createApp(App).mount("#app");

I want to change innerHTML of props and children dynamic at same time.

What is expected?

no Error and use innerHTML if provided or children content.

What is actually happening?

throw an error.

TypeError Cannot read properties of undefined (reading '__asyncLoader')

<!-- generated by vue-issues. DO NOT REMOVE -->

The two patches

Our patch+353 −21
packages/runtime-core/__tests__/hydration.spec.tsindex 537ba236c..4e599dc07 100644@@ -91,6 +91,49 @@ describe('SSR hydration', () => {     expect(container.textContent).toBe('bar')   }) +  test('element w/ innerHTML and text children', async () => {+    const html = ref<string | undefined>('<b>x</b>')+    const { container } = mountWithHydration('<div><b>x</b></div>', () =>+      h('div', { innerHTML: html.value }, 'a'),+    )+    expect(container.innerHTML).toBe(`<div><b>x</b></div>`)+    expect(`Hydration text content mismatch`).not.toHaveBeenWarned()++    html.value = undefined+    await nextTick()+    expect(container.innerHTML).toBe(`<div>a</div>`)+  })++  test('element w/ innerHTML and array children', async () => {+    const mounted = vi.fn()+    const unmounted = vi.fn()+    const Comp = { render: () => 'comp', mounted, unmounted }+    const html = ref<string | undefined>('<b>x</b>')+    const { container } = mountWithHydration('<div><b>x</b></div>', () =>+      h('div', { innerHTML: html.value }, [h('span', 'a'), h(Comp)]),+    )+    expect(container.innerHTML).toBe(`<div><b>x</b></div>`)+    expect(mounted).not.toHaveBeenCalled()++    html.value = undefined+    await nextTick()+    expect(container.innerHTML).toBe(`<div><span>a</span>comp</div>`)+    expect(mounted).toHaveBeenCalledTimes(1)++    html.value = '<i>y</i>'+    await nextTick()+    expect(container.innerHTML).toBe(`<div><i>y</i></div>`)+    expect(unmounted).toHaveBeenCalledTimes(1)+  })++  test('element w/ empty innerHTML and array children', async () => {+    const { container } = mountWithHydration('<div></div>', () =>+      h('div', { innerHTML: '' }, [h('span', 'a')]),+    )+    expect(container.innerHTML).toBe(`<div></div>`)+    expect(`Hydration children mismatch`).not.toHaveBeenWarned()+  })+   test('empty text', async () => {     const { container } = mountWithHydration('<div></div>', () =>       h('div', createTextVNode('')),packages/runtime-core/src/hydration.tsindex aaf41064f..aa75b899f 100644@@ -32,7 +32,11 @@ import {   normalizeStyle,   stringifyStyle, } from '@vue/shared'-import { type RendererInternals, needTransition } from './renderer'+import {+  type RendererInternals,+  hasContentOverride,+  needTransition,+} from './renderer' import { setRef } from './rendererTemplateRef' import {   type SuspenseBoundary,@@ -429,11 +433,10 @@ export function createHydrationFunctions(       }        // children-      if (-        shapeFlag & ShapeFlags.ARRAY_CHILDREN &&-        // skip if element has innerHTML / textContent-        !(props && (props.innerHTML || props.textContent))-      ) {+      if (hasContentOverride(props)) {+        // skip if element has innerHTML / textContent, its content comes from+        // the prop and children are not mounted (consistent with mountElement)+      } else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {         let next = hydrateChildren(           el.firstChild,           vnode,packages/runtime-core/src/renderer.tsindex c0fab7373..08052950a 100644@@ -11,6 +11,7 @@ import {   createVNode,   invokeVNodeHook,   isSameVNodeType,+  isVNode,   normalizeVNode, } from './vnode' import {@@ -674,7 +675,11 @@ function baseCreateRenderer(      // mount children first, since some props may rely on child content     // being already rendered, e.g. `<select value>`-    if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {+    // children are not mounted when innerHTML / textContent provides the+    // element's content (consistent with SSR and hydration)+    if (hasContentOverride(props)) {+      // content is set by the innerHTML / textContent prop below+    } else if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {       hostSetElementText(el, vnode.children as string)     } else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {       mountChildren(@@ -869,16 +874,49 @@ function baseCreateRenderer(       dynamicChildren = null     } -    // #9135 innerHTML / textContent unset needs to happen before possible-    // new children mount-    if (-      (oldProps.innerHTML && newProps.innerHTML == null) ||-      (oldProps.textContent && newProps.textContent == null)-    ) {-      hostSetElementText(el, '')-    }+    // children are only mounted while neither innerHTML nor textContent+    // provides the element's content+    const oldContentOverride = hasContentOverride(oldProps)+    const newContentOverride = hasContentOverride(newProps) -    if (dynamicChildren) {+    if (oldContentOverride || newContentOverride) {+      if (!oldContentOverride) {+        // children -> innerHTML / textContent: unmount old children, the new+        // content is set when patching props below+        if (n1.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {+          unmountChildren(+            n1.children as VNode[],+            parentComponent,+            parentSuspense,+            true,+          )+        }+        // new children may have already been patched against the old ones+        // through a parent block's dynamicChildren, reset them to unmounted+        if (n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {+          resetMountedState(n2.children as VNodeArrayChildren)+        }+      } else if (!newContentOverride) {+        // #9135 innerHTML / textContent -> children: old children were never+        // mounted, clear the content and mount the new children fresh+        hostSetElementText(el, '')+        if (n2.shapeFlag & ShapeFlags.TEXT_CHILDREN) {+          hostSetElementText(el, n2.children as string)+        } else if (n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {+          mountChildren(+            n2.children as VNodeArrayChildren,+            el,+            null,+            parentComponent,+            parentSuspense,+            resolveChildrenNamespace(n2, namespace),+            slotScopeIds,+            optimized,+          )+        }+      }+      // otherwise both use innerHTML / textContent: children stay unmounted+    } else if (dynamicChildren) {       patchBlockChildren(         n1.dynamicChildren!,         dynamicChildren,@@ -953,7 +991,7 @@ function baseCreateRenderer(        // text       // This flag is matched when the element has only dynamic text children.-      if (patchFlag & PatchFlags.TEXT) {+      if (patchFlag & PatchFlags.TEXT && !newContentOverride) {         if (n1.children !== n2.children) {           hostSetElementText(el, n2.children as string)         }@@ -984,6 +1022,10 @@ function baseCreateRenderer(     for (let i = 0; i < newChildren.length; i++) {       const oldVNode = oldChildren[i]       const newVNode = newChildren[i]+      // children of an element using innerHTML / textContent are tracked by+      // the parent block but never mounted, the element itself mounts them+      // once the content prop is removed+      if (isNeverMounted(oldVNode)) continue       // Determine the container (parent element) for the patch.       const container =         // oldVNode may be an errored async setup() component inside Suspense@@ -2145,6 +2187,10 @@ function baseCreateRenderer(     doRemove = false,     optimized = false,   ) => {+    // children of an element using innerHTML / textContent may be reached+    // through a parent block's dynamicChildren without ever being mounted+    if (isNeverMounted(vnode)) return+     const {       type,       props,@@ -2210,6 +2256,9 @@ function baseCreateRenderer(           internals,           doRemove,         )+      } else if (shapeFlag & ShapeFlags.ELEMENT && hasContentOverride(props)) {+        // children of an element using innerHTML / textContent are never+        // mounted, so there is nothing to unmount       } else if (         dynamicChildren &&         // #5154@@ -2471,6 +2520,33 @@ function baseCreateRenderer(   } } +/**+ * Whether the element's content is provided by an `innerHTML` / `textContent`+ * prop, in which case its vnode children are not mounted.+ */+export function hasContentOverride(props: Data | null): boolean {+  return !!props && (props.innerHTML != null || props.textContent != null)+}++function isNeverMounted(vnode: VNode): boolean {+  // mounted vnodes always have an el, except errored async setup() components+  // inside Suspense, which still have an instance+  return !vnode.el && !vnode.component+}++function resetMountedState(children: VNodeArrayChildren): void {+  for (let i = 0; i < children.length; i++) {+    const child = children[i]+    if (isVNode(child)) {+      child.el = null+      child.component = null+      if (isArray(child.children)) resetMountedState(child.children)+    } else if (isArray(child)) {+      resetMountedState(child)+    }+  }+}+ function resolveChildrenNamespace(   { type, props }: VNode,   currentNamespace: ElementNamespace,@@ -2538,7 +2614,13 @@ export function traverseStaticChildren(           c2 = ch2[i] = cloneIfMounted(ch2[i] as VNode)           c2.el = c1.el         }-        if (!shallow && c2.patchFlag !== PatchFlags.BAIL)+        if (+          !shallow &&+          c2.patchFlag !== PatchFlags.BAIL &&+          // children of innerHTML / textContent elements are not mounted+          !hasContentOverride(c1.props) &&+          !hasContentOverride(c2.props)+        )           traverseStaticChildren(c1, c2)       }       // #6852 also inherit for text nodespackages/runtime-dom/__tests__/patchProps.spec.tsindex 304d9f9c1..17def5860 100644@@ -1,5 +1,6 @@ import { patchProp } from '../src/patchProp' import {+  createApp,   h,   nextTick,   ref,@@ -165,6 +166,119 @@ describe('runtime-dom: props patching', () => {     expect(root.innerHTML).toBe(`<div></div>`)   }) +  test('innerHTML w/ undefined value and children', () => {+    const root = document.createElement('div')+    createApp({+      render: () => h('div', { innerHTML: undefined }, 'a'),+    }).mount(root)+    expect(root.innerHTML).toBe(`<div>a</div>`)+  })++  test('toggle innerHTML w/ text children', async () => {+    const root = document.createElement('div')+    const html = ref<string | undefined>(undefined)+    const text = ref('a')+    createApp({+      render: () => h('div', { innerHTML: html.value }, text.value),+    }).mount(root)+    expect(root.innerHTML).toBe(`<div>a</div>`)++    html.value = '<b>x</b>'+    await nextTick()+    expect(root.innerHTML).toBe(`<div><b>x</b></div>`)++    // children updates must not overwrite innerHTML content+    text.value = 'b'+    await nextTick()+    expect(root.innerHTML).toBe(`<div><b>x</b></div>`)++    html.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(`<div>b</div>`)++    text.value = 'c'+    await nextTick()+    expect(root.innerHTML).toBe(`<div>c</div>`)+  })++  test('toggle innerHTML w/ array children', async () => {+    const mounted = vi.fn()+    const unmounted = vi.fn()+    const Comp = { render: () => 'comp', mounted, unmounted }+    const root = document.createElement('div')+    const html = ref<string | undefined>('<b>x</b>')+    const items = ref(['a'])+    createApp({+      render: () =>+        h('div', { innerHTML: html.value }, [+          ...items.value.map(i => h('span', { key: i }, i)),+          h(Comp),+        ]),+    }).mount(root)+    expect(root.innerHTML).toBe(`<div><b>x</b></div>`)+    expect(mounted).not.toHaveBeenCalled()++    // children updates must not leak into innerHTML content+    items.value = ['a', 'b']+    await nextTick()+    expect(root.innerHTML).toBe(`<div><b>x</b></div>`)++    html.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(`<div><span>a</span><span>b</span>comp</div>`)+    expect(mounted).toHaveBeenCalledTimes(1)++    items.value = ['b', 'c']+    await nextTick()+    expect(root.innerHTML).toBe(`<div><span>b</span><span>c</span>comp</div>`)++    html.value = '<i>y</i>'+    await nextTick()+    expect(root.innerHTML).toBe(`<div><i>y</i></div>`)+    expect(unmounted).toHaveBeenCalledTimes(1)++    html.value = ''+    await nextTick()+    expect(root.innerHTML).toBe(`<div></div>`)++    html.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(`<div><span>b</span><span>c</span>comp</div>`)+    expect(mounted).toHaveBeenCalledTimes(2)++    render(null, root)+    expect(unmounted).toHaveBeenCalledTimes(2)+  })++  test('unmount element w/ innerHTML and component children', () => {+    const unmounted = vi.fn()+    const Comp = { render: () => 'comp', unmounted }+    const root = document.createElement('div')+    render(h('div', { innerHTML: 'x' }, [h(Comp)]), root)+    expect(root.innerHTML).toBe(`<div>x</div>`)+    render(null, root)+    expect(root.innerHTML).toBe(``)+    // the child was never mounted+    expect(unmounted).not.toHaveBeenCalled()+  })++  test('toggle textContent w/ array children', async () => {+    const root = document.createElement('div')+    const content = ref<string | undefined>(undefined)+    createApp({+      render: () => h('div', { textContent: content.value }, [h('span', 'a')]),+    }).mount(root)+    expect(root.innerHTML).toBe(`<div><span>a</span></div>`)++    content.value = '<b>x</b>'+    await nextTick()+    expect(root.innerHTML).toBe(`<div>&lt;b&gt;x&lt;/b&gt;</div>`)++    content.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(`<div><span>a</span></div>`)+  })+   test('textContent unmount prev children', () => {     const fn = vi.fn()     const comp = {packages/server-renderer/__tests__/render.spec.tsindex f537a6219..180dc3b71 100644@@ -680,6 +680,28 @@ function testRender(type: string, render: typeof renderToString) {         ).toBe(`<div>${escapeHtml(`<span>hello</span>`)}</div>`)       }) +      test('innerHTML w/ undefined value', async () => {+        expect(+          await render(h('div', { innerHTML: undefined }, 'children')),+        ).toBe(`<div>children</div>`)+      })++      test('empty innerHTML / textContent', async () => {+        // consistent with client-side rendering, where the prop takes over+        expect(await render(h('div', { innerHTML: '' }, 'ignored'))).toBe(+          `<div></div>`,+        )+        expect(await render(h('div', { textContent: '' }, 'ignored'))).toBe(+          `<div></div>`,+        )+      })++      test('non-string innerHTML', async () => {+        expect(await render(h('div', { innerHTML: 0 }, 'ignored'))).toBe(+          `<div>0</div>`,+        )+      })+       test('textarea value', async () => {         expect(           await render(packages/server-renderer/src/render.tsindex c2bde4d1e..296a8a7fd 100644@@ -350,10 +350,10 @@ function renderElementVNode(   if (!isVoidTag(tag)) {     let hasChildrenOverride = false     if (props) {-      if (props.innerHTML) {+      if (props.innerHTML != null) {         hasChildrenOverride = true-        push(props.innerHTML)-      } else if (props.textContent) {+        push(String(props.innerHTML))+      } else if (props.textContent != null) {         hasChildrenOverride = true         push(escapeHtml(props.textContent))       } else if (tag === 'textarea' && props.value) {packages/vue/__tests__/index.spec.tsindex 79e48b775..ceb1f39dd 100644@@ -347,4 +347,72 @@ describe('compiler + runtime integration', () => {     app.mount(root)     expect(root.innerHTML).toBe('<div>60000000100000111</div>')   })++  // children of an element with a dynamic innerHTML binding are tracked by+  // the parent block but not mounted while innerHTML is set+  test(':innerHTML binding with dynamic children inside a block', async () => {+    const mounted = vi.fn()+    const unmounted = vi.fn()+    const Child = {+      props: ['msg'],+      template: `<i>{{ msg }}</i>`,+      mounted,+      unmounted,+    }+    const html = ref<string | undefined>('<b>h</b>')+    const c = ref('a')+    const msg = ref('m')+    const root = document.createElement('div')+    const app = createApp({+      components: { Child },+      setup: () => ({ html, c, msg }),+      template: `<div><p :innerHTML="html"><span :class="c">{{ msg }}</span> x {{ msg }}<Child :msg="msg"/></p></div>`,+    })+    app.mount(root)+    expect(root.innerHTML).toBe('<div><p><b>h</b></p></div>')+    expect(mounted).toHaveBeenCalledTimes(0)++    c.value = 'b'+    msg.value = 'n'+    await nextTick()+    expect(root.innerHTML).toBe('<div><p><b>h</b></p></div>')++    html.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(+      '<div><p><span class="b">n</span> x n<i>n</i></p></div>',+    )+    expect(mounted).toHaveBeenCalledTimes(1)++    msg.value = 'o'+    await nextTick()+    expect(root.innerHTML).toBe(+      '<div><p><span class="b">o</span> x o<i>o</i></p></div>',+    )++    html.value = '<u>z</u>'+    await nextTick()+    expect(root.innerHTML).toBe('<div><p><u>z</u></p></div>')+    expect(unmounted).toHaveBeenCalledTimes(1)++    msg.value = 'q'+    await nextTick()+    expect(root.innerHTML).toBe('<div><p><u>z</u></p></div>')++    html.value = undefined+    await nextTick()+    expect(root.innerHTML).toBe(+      '<div><p><span class="b">q</span> x q<i>q</i></p></div>',+    )+    expect(mounted).toHaveBeenCalledTimes(2)++    html.value = '<u>w</u>'+    await nextTick()+    expect(unmounted).toHaveBeenCalledTimes(2)++    app.unmount()+    expect(root.innerHTML).toBe('')+    expect(mounted).toHaveBeenCalledTimes(2)+    expect(unmounted).toHaveBeenCalledTimes(2)+  }) }) 
Merged fix · PR #15194+81 −0
packages/runtime-core/__tests__/vnode.spec.tsindex 3a88f302b..000ded438 100644@@ -92,6 +92,50 @@ describe('vnode', () => {     expect(`VNode created with invalid key (NaN)`).toHaveBeenWarned()   }) +  // #5081+  describe('children overridden by innerHTML / textContent', () => {+    test('warn on text children', () => {+      createVNode('div', { innerHTML: '<span/>' }, 'hello')+      expect(+        `The \`innerHTML\` prop on <div> will override its children`,+      ).toHaveBeenWarned()+    })++    test('warn on array children', () => {+      createVNode('div', { innerHTML: '<span/>' }, [createVNode('span')])+      expect(+        `The \`innerHTML\` prop on <div> will override its children`,+      ).toHaveBeenWarned()+    })++    test('warn on textContent', () => {+      createVNode('div', { textContent: 'text' }, 'hello')+      expect(+        `The \`textContent\` prop on <div> will override its children`,+      ).toHaveBeenWarned()+    })++    test('no warning when the prop is nullish', () => {+      createVNode('div', { innerHTML: undefined }, 'hello')+      createVNode('div', { innerHTML: null }, 'hello')+      createVNode('div', { textContent: undefined }, 'hello')+      expect(`will override its children`).not.toHaveBeenWarned()+    })++    test('no warning without renderable children', () => {+      createVNode('div', { innerHTML: '<span/>' })+      createVNode('div', { innerHTML: '<span/>' }, '')+      createVNode('div', { innerHTML: '<span/>' }, [])+      expect(`will override its children`).not.toHaveBeenWarned()+    })++    test('no warning for component vnodes', () => {+      const Comp = { props: ['innerHTML'], render: () => null }+      createVNode(Comp, { innerHTML: '<span/>' }, { default: () => 'slot' })+      expect(`will override its children`).not.toHaveBeenWarned()+    })+  })+   test('create with class component', () => {     class Component {       $props: anypackages/runtime-core/src/vnode.tsindex e9745c503..30d7fdfda 100644@@ -499,6 +499,25 @@ function createBaseVNode(     warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type)   } +  // #5081 validate children that will be silently discarded by innerHTML /+  // textContent. The template compiler already errors on `v-html` / `v-text`+  // used with children, but render functions have no such check.+  if (__DEV__ && props && vnode.shapeFlag & ShapeFlags.ELEMENT) {+    const overwritingProp =+      props.innerHTML != null+        ? 'innerHTML'+        : props.textContent != null+          ? 'textContent'+          : null+    if (overwritingProp && hasContentChildren(vnode.children)) {+      warn(+        `The \`${overwritingProp}\` prop on <${vnode.type as string}> will ` ++          `override its children. Remove either the \`${overwritingProp}\` ` ++          `prop or the children.`,+      )+    }+  }+   // track vnode for block tree   if (     isBlockTreeEnabled > 0 &&@@ -528,6 +547,18 @@ function createBaseVNode(  export { createBaseVNode as createElementVNode } +/**+ * dev only+ * Whether children would actually render something. Empty text and empty+ * arrays are ignored, mirroring the compiler's `node.children.length` check+ * for `v-html` / `v-text`.+ */+function hasContentChildren(children: VNode['children']): boolean {+  if (isString(children)) return children !== ''+  if (isArray(children)) return children.length > 0+  return false+}+ export const createVNode = (   __DEV__ ? createVNodeWithArgsTransform : _createVNode ) as typeof _createVNodepackages/server-renderer/__tests__/render.spec.tsindex f537a6219..37de08bd4 100644@@ -664,6 +664,9 @@ function testRender(type: string, render: typeof renderToString) {             ),           ),         ).toBe(`<div><span>hello</span></div>`)+        expect(+          `The \`innerHTML\` prop on <div> will override its children`,+        ).toHaveBeenWarned()       })        test('textContent', async () => {@@ -678,6 +681,9 @@ function testRender(type: string, render: typeof renderToString) {             ),           ),         ).toBe(`<div>${escapeHtml(`<span>hello</span>`)}</div>`)+        expect(+          `The \`textContent\` prop on <div> will override its children`,+        ).toHaveBeenWarned()       })        test('textarea value', async () => {