Backtestsvuerun-20261002-115633#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.
Neither patch changes the rendering logic that the issue implicates. Patch A is tests-only. Patch B adds a dev-only warning in createBaseVNode. Judged on correctness, neither visibly fixes the `__asyncLoader` crash in this diff. That means either both depend on the behavior already working in the current codebase, or both fail to fix it.
Given that, the deciding question is which patch better captures the issue's ask: 'no error, use innerHTML if provided or children content.'
Patch A tests exactly that behavior:
- `h('div', { innerHTML: undefined }, 'a')` renders `<div>a</div>`, and the same with array children.
- innerHTML and children toggle dynamically in both directions (children → html → children), which is the user's stated use case.
- The same scenarios are covered for textContent.
These tests would fail if the crash or the stale-content behavior were present. They act as meaningful regression guards for the reported scenario.
Patch B solves a different problem. It warns when a non-nullish innerHTML or textContent is combined with renderable children. Its 'no warning when nullish' test is tangentially relevant, but it only checks that no warning fires, not that rendering succeeds. It never exercises the crashing render path or the dynamic switch. The new warning also adds behavior beyond the issue's ask and requires touching SSR tests to expect warnings. For users who intentionally pass both, as the issue's author wants to do dynamically, it could produce noisy warnings whenever innerHTML is set while children are still supplied.
Patch A targets the reported scenario directly with relevant tests and adds no risk. Patch B adds unrelated diagnostics without addressing or verifying the crash. A is the better patch, though neither contains a source-level 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
4m 45s
Wall-clock time in the container
Full test suite
No new failures
3,646 passed · 6 skipped · 3,652 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
58vs 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-dom/__tests__/patchProps.spec.tsindex 304d9f9c1..67bb25119 100644@@ -165,6 +165,64 @@ describe('runtime-dom: props patching', () => { expect(root.innerHTML).toBe(`<div></div>`) }) + test('innerHTML w/ undefined value and children', () => {+ const root = document.createElement('div')+ render(h('div', { innerHTML: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ render(h('div', { innerHTML: undefined }, [h('span', 'b')]), root)+ expect(root.innerHTML).toBe(`<div><span>b</span></div>`)+ })++ test('patch innerHTML and children dynamically', async () => {+ const root = document.createElement('div')+ const html = ref<string | undefined>(undefined)+ const Comp = {+ render: () =>+ h(+ 'div',+ { innerHTML: html.value },+ html.value == null ? [h('span', 'child')] : undefined,+ ),+ }+ render(h(Comp), root)+ expect(root.innerHTML).toBe(`<div><span>child</span></div>`)++ html.value = '<b>html</b>'+ await nextTick()+ expect(root.innerHTML).toBe(`<div><b>html</b></div>`)++ html.value = undefined+ await nextTick()+ expect(root.innerHTML).toBe(`<div><span>child</span></div>`)+ })++ test('textContent w/ undefined value and children', async () => {+ const root = document.createElement('div')+ render(h('div', { textContent: undefined }, 'a'), root)+ expect(root.innerHTML).toBe(`<div>a</div>`)++ const text = ref<string | undefined>(undefined)+ const Comp = {+ render: () =>+ h(+ 'div',+ { textContent: text.value },+ text.value == null ? [h('span', 'child')] : undefined,+ ),+ }+ render(h(Comp), root)+ expect(root.innerHTML).toBe(`<div><span>child</span></div>`)++ text.value = 'text'+ await nextTick()+ expect(root.innerHTML).toBe(`<div>text</div>`)++ text.value = undefined+ await nextTick()+ expect(root.innerHTML).toBe(`<div><span>child</span></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 () => {