Backtestsvuerun-20261013-093701#5081

Issue #5081 Merged fix PR #15194 Run 13 Oct 2026 · run-20261013-093701 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 asks for an element with both an `innerHTML` prop and children to work without error. When `innerHTML` is set it should win, and when it is nullish the children should render. The reporter specifically wants to toggle the two dynamically.

Patch A changes the renderer's `patchElement`. When the old vnode had an `innerHTML`/`textContent` override, the stale children DOM cannot be diffed in place. Patch A clears the element, unmounts the old children (skipping ones never mounted because hydration skipped them), mounts the new children fresh, and re-applies an unchanged override on top. It also stops the compiler's `PatchFlags.TEXT` fast path from overwriting an active `innerHTML`. Together these cover the reported scenario: `undefined` innerHTML with text children, and toggling in both directions with text, keyed array, component and hydrated children. Its tests exercise real failure modes of the old code, such as:
- an unset override with unchanged children leaving the element empty
- children reordered while hidden
- dynamic text clobbering `innerHTML` in compiled templates
- the hydration edge case

The change is fairly involved, and the `filter(c => c.el)` is a bit ad hoc, but it is a coherent root-cause fix for the behaviour the issue describes.

Patch B makes no runtime behaviour change. It only adds a dev-mode warning when a non-nullish `innerHTML`/`textContent` is combined with children. That does nothing for the dynamic-toggle use case the reporter explicitly wants, and it would emit warnings whenever the override is active in exactly that pattern. Its tests only check the warnings, not correct rendering or updates.

On correctness, which is weighed first, Patch A addresses the issue and Patch B does not, so Patch A is clearly better.

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

8m 46s

Wall-clock time in the container

Full test suite

No new failures

1,760 passed · 1 skipped · 1,761 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

205vs 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+197 −8
packages/runtime-core/__tests__/hydration.spec.tsindex 537ba236c..589283ef9 100644@@ -1756,6 +1756,21 @@ describe('SSR hydration', () => {     expect(root.value).toBe(container.firstChild)   }) +  test('update element w/ innerHTML and component children skipped during hydration', async () => {+    const container = document.createElement('div')+    container.innerHTML = '<div>x</div>'+    const content = ref<string | undefined>('x')+    const Child = { render: () => h('span', 'child') }+    createSSRApp({+      render: () => h('div', { innerHTML: content.value }, [h(Child)]),+    }).mount(container)+    expect(container.innerHTML).toBe('<div>x</div>')++    content.value = undefined+    await nextTick()+    expect(container.innerHTML).toBe('<div><span>child</span></div>')+  })+   // #5728   test('empty text node in slot', () => {     const Comp = {packages/runtime-core/src/renderer.tsindex c0fab7373..2a9da6d76 100644@@ -300,6 +300,12 @@ export const queuePostRenderEffect: (     : queueEffectWithSuspense   : queuePostFlushCb +const contentOverrideKeys = ['innerHTML', 'textContent'] as const++function hasContentOverride(props: Data): boolean {+  return props.innerHTML != null || props.textContent != null+}+ /**  * The createRenderer function accepts two generic arguments:  * HostNode and HostElement, corresponding to Node and Element types in the@@ -869,16 +875,61 @@ 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)+      hasContentOverride(oldProps) &&+      (n1.shapeFlag | n2.shapeFlag) &+        (ShapeFlags.TEXT_CHILDREN | ShapeFlags.ARRAY_CHILDREN)     ) {+      // innerHTML / textContent on the old vnode replaced the DOM of its+      // children, so they can't be diffed in place (#9135). Clear the element,+      // unmount the old children and mount the new ones fresh.       hostSetElementText(el, '')-    }--    if (dynamicChildren) {+      if (n1.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {+        // children skipped during hydration were never mounted+        unmountChildren(+          (n1.children as VNode[]).filter(c => c.el),+          parentComponent,+          parentSuspense,+        )+      }+      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,+          false,+        )+      }+      // re-apply an unchanged override on top of the remounted children,+      // patchProps below only patches it when its value changed+      for (const key of contentOverrideKeys) {+        if (newProps[key] != null && newProps[key] === oldProps[key]) {+          hostPatchProp(+            el,+            key,+            null,+            newProps[key],+            namespace,+            parentComponent,+          )+        }+      }+    } else if (hasContentOverride(oldProps)) {+      // #9135 no children to remount, only clear an unset innerHTML /+      // textContent so an unchanged one keeps its DOM+      if (+        (oldProps.innerHTML != null && newProps.innerHTML == null) ||+        (oldProps.textContent != null && newProps.textContent == null)+      ) {+        hostSetElementText(el, '')+      }+    } else if (dynamicChildren) {       patchBlockChildren(         n1.dynamicChildren!,         dynamicChildren,@@ -953,7 +1004,8 @@ function baseCreateRenderer(        // text       // This flag is matched when the element has only dynamic text children.-      if (patchFlag & PatchFlags.TEXT) {+      // skipped when innerHTML / textContent overrides the children+      if (patchFlag & PatchFlags.TEXT && !hasContentOverride(newProps)) {         if (n1.children !== n2.children) {           hostSetElementText(el, n2.children as string)         }packages/runtime-dom/__tests__/patchProps.spec.tsindex 304d9f9c1..fb3648aba 100644@@ -165,6 +165,105 @@ describe('runtime-dom: props patching', () => {     expect(root.innerHTML).toBe(`<div></div>`)   }) +  test('innerHTML w/ undefined value and text children', () => {+    const root = document.createElement('div')+    render(h('div', { innerHTML: undefined }, 'a'), root)+    expect(root.innerHTML).toBe(`<div>a</div>`)+  })++  for (const key of ['innerHTML', 'textContent'] as const) {+    test(`toggle ${key} w/ text children`, async () => {+      const root = document.createElement('div')+      const content = ref<string | undefined>(undefined)+      const text = ref('a')+      const Comp = {+        render: () => h('div', { [key]: content.value }, text.value),+      }+      render(h(Comp), root)+      expect(root.innerHTML).toBe(`<div>a</div>`)++      content.value = 'x'+      await nextTick()+      expect(root.innerHTML).toBe(`<div>x</div>`)++      // unset with unchanged children+      content.value = undefined+      await nextTick()+      expect(root.innerHTML).toBe(`<div>a</div>`)++      content.value = 'y'+      text.value = 'b'+      await nextTick()+      expect(root.innerHTML).toBe(`<div>y</div>`)++      content.value = undefined+      await nextTick()+      expect(root.innerHTML).toBe(`<div>b</div>`)+    })++    test(`toggle ${key} w/ keyed array children`, async () => {+      const root = document.createElement('div')+      const content = ref<string | undefined>(undefined)+      const order = ref([1, 2])+      const unmounted = vi.fn()+      const Child = {+        props: ['n'],+        render(this: any) {+          return h('span', this.n)+        },+        unmounted,+      }+      const Comp = {+        render: () =>+          h(+            'div',+            { [key]: content.value },+            order.value.map(n => h(Child, { key: n, n })),+          ),+      }+      render(h(Comp), root)+      expect(root.innerHTML).toBe(`<div><span>1</span><span>2</span></div>`)++      content.value = 'x'+      await nextTick()+      expect(root.innerHTML).toBe(`<div>x</div>`)++      content.value = undefined+      await nextTick()+      expect(root.innerHTML).toBe(`<div><span>1</span><span>2</span></div>`)+      expect(unmounted).toHaveBeenCalledTimes(2)++      // reorder + add children while the override stays the same+      content.value = 'x'+      await nextTick()+      order.value = [3, 2, 1]+      await nextTick()+      expect(root.innerHTML).toBe(`<div>x</div>`)++      content.value = undefined+      await nextTick()+      expect(root.innerHTML).toBe(+        `<div><span>3</span><span>2</span><span>1</span></div>`,+      )+    })+  }++  test('unchanged innerHTML keeps its DOM on re-render', async () => {+    const root = document.createElement('div')+    const count = ref(0)+    const Comp = {+      render: () => [h('div', { innerHTML: '<b>x</b>' }), count.value],+    }+    render(h(Comp), root)+    const b = root.querySelector('b')+    expect(b).not.toBe(null)++    count.value+++    await nextTick()+    expect(root.innerHTML).toBe(`<div><b>x</b></div>1`)+    expect(root.querySelector('b')).toBe(b)+  })+   test('textContent unmount prev children', () => {     const fn = vi.fn()     const comp = {packages/vue/__tests__/index.spec.tsindex 79e48b775..ac0813974 100644@@ -16,6 +16,29 @@ describe('compiler + runtime integration', () => {     expect(container.innerHTML).toBe(`0`)   }) +  it('dynamic innerHTML should override dynamic text children', async () => {+    const container = document.createElement('div')+    const html = ref<string | undefined>('x')+    const msg = ref('a')+    createApp({+      template: `<div :innerHTML="html">{{ msg }}</div>`,+      setup: () => ({ html, msg }),+    }).mount(container)+    expect(container.innerHTML).toBe(`<div>x</div>`)++    msg.value = 'b'+    await nextTick()+    expect(container.innerHTML).toBe(`<div>x</div>`)++    html.value = undefined+    await nextTick()+    expect(container.innerHTML).toBe(`<div>b</div>`)++    html.value = 'y'+    await nextTick()+    expect(container.innerHTML).toBe(`<div>y</div>`)+  })+   it('keep-alive with compiler + runtime integration', async () => {     const container = document.createElement('div')     const one = { 
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 () => {