Backtestsvuerun-20261003-231210#5081
Throw an error on createVNode with using innerHTML and children at the same time
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Patch A fixes the behavior the issue asks for, and Patch B does not.
**Patch A.** The issue wants an element whose `innerHTML` is toggled between a value and `undefined` to fall back to its children. Patch A changes `patchElement` in two ways:
- The unset check now uses `!= null` instead of truthiness, so going from an empty-string `innerHTML` or `textContent` to `undefined` is handled.
- When the prop is removed and the new children are text, it restores that text immediately. Without this, the text-children diff sees the old and new text as equal, skips the update, and leaves the element empty.
This is the real root cause of the dynamic scenario the user describes ("change innerHTML of props and children dynamic at same time"). Its tests are behavioral and would fail before the change. Examples include `innerHTML: '<span>foo</span>'` → `undefined` with the same `'a'` child expecting `<div>a</div>`, the empty-string → `undefined` case, and the textContent variants. It also covers mount with `innerHTML: undefined`, array children, and a reactive component case. The change is small and sits next to the existing #9135 logic.
**Patch B.** It only adds a dev-mode warning when a non-nullish `innerHTML`/`textContent` is combined with children. It deliberately skips the nullish case, which is exactly the issue's reproduction (`innerHTML: undefined`), so it does nothing for that scenario. It also does not fix the update bug where the text fails to reappear after the prop is removed. Its tests only check that warnings appear, not rendering correctness. Adding warnings to existing SSR tests is unrelated churn. It also contradicts the user's stated intent to use both together, with `innerHTML` taking precedence when it is set.
Patch A is clearly the better fix.
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 35s
Wall-clock time in the container
Full test suite
No new failures
3,648 passed · 6 skipped · 3,654 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
99vs 81 merged
Changed lines, ours vs merged
The issue
View on GitHubVersion
3.2.24
Reproduction link
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
packages/runtime-core/src/renderer.tsindex c0fab7373..bd0f27420 100644@@ -872,10 +872,15 @@ function baseCreateRenderer( // #9135 innerHTML / textContent unset needs to happen before possible // new children mount if (- (oldProps.innerHTML && newProps.innerHTML == null) ||- (oldProps.textContent && newProps.textContent == null)+ (oldProps.innerHTML != null && newProps.innerHTML == null) ||+ (oldProps.textContent != null && newProps.textContent == null) ) {- hostSetElementText(el, '')+ // #5093 if the new children are text, restore them here since the+ // children diff below skips unchanged text children+ hostSetElementText(+ el,+ n2.shapeFlag & ShapeFlags.TEXT_CHILDREN ? (n2.children as string) : '',+ ) } if (dynamicChildren) {packages/runtime-dom/__tests__/patchProps.spec.tsindex 304d9f9c1..4a9190e15 100644@@ -165,6 +165,94 @@ describe('runtime-dom: props patching', () => { expect(root.innerHTML).toBe(`<div></div>`) }) + // #5093+ test('innerHTML w/ undefined value and text children', async () => {+ const root = document.createElement('div')+ render(h('div', { innerHTML: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ render(h('div', { innerHTML: '<span>foo</span>' }, 'a'), root)+ expect(root.innerHTML).toBe(`<div><span>foo</span></div>`)++ render(h('div', { innerHTML: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ render(h('div', { innerHTML: undefined }, 'b'), root)+ expect(root.innerHTML).toBe(`<div>b</div>`)+ })++ // #5093+ test('innerHTML w/ undefined value and dynamic props/children', async () => {+ const root = document.createElement('div')+ const html = ref<string | undefined>(undefined)+ const text = ref('a')+ const Comp = {+ render: () => h('div', { innerHTML: html.value }, text.value),+ }+ render(h(Comp), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ html.value = 'foo'+ text.value = 'b'+ await nextTick()+ expect(root.innerHTML).toBe(`<div>foo</div>`)++ html.value = undefined+ await nextTick()+ expect(root.innerHTML).toBe(`<div>b</div>`)++ render(null, root)+ expect(root.innerHTML).toBe(``)+ })++ // #5093+ test('innerHTML w/ undefined value and array children', async () => {+ const fn = vi.fn()+ const comp = {+ render: () => 'foo',+ unmounted: fn,+ }+ const root = document.createElement('div')+ render(h('div', { innerHTML: undefined }, [h(comp)]), root)+ expect(root.innerHTML).toBe(`<div>foo</div>`)++ render(h('div', { innerHTML: undefined }, [h('span', 'bar')]), root)+ expect(root.innerHTML).toBe(`<div><span>bar</span></div>`)+ expect(fn).toHaveBeenCalledTimes(1)++ render(null, root)+ expect(root.innerHTML).toBe(``)+ })++ // #5093+ test('textContent w/ undefined value and text children', async () => {+ const root = document.createElement('div')+ render(h('div', { textContent: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ render(h('div', { textContent: 'foo' }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>foo</div>`)++ render(h('div', { textContent: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)+ })++ // #5093+ test('innerHTML/textContent w/ empty string value then undefined', () => {+ const root = document.createElement('div')+ render(h('div', { innerHTML: '' }, 'a'), root)+ expect(root.innerHTML).toBe(`<div></div>`)++ render(h('div', { innerHTML: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ render(h('div', { textContent: '' }, 'a'), root)+ expect(root.innerHTML).toBe(`<div></div>`)++ render(h('div', { textContent: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)+ })+ test('textContent unmount prev children', () => { const fn = vi.fn() const comp = {
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 () => {