Skip to content

Commit cb34b28

Browse files
authoredSep 26, 2024··
fix(runtime-core): avoid rendering plain object as VNode (#12038)
close #12035 close vitejs/vite-plugin-vue#353
1 parent faf55a1 commit cb34b28

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎packages/runtime-core/__tests__/rendererChildren.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ test('array children -> text children', () => {
6565
expect(inner(root)).toBe('<div>hello</div>')
6666
})
6767

68+
test('plain object child', () => {
69+
const root = nodeOps.createElement('div')
70+
const foo = { foo: '1' }
71+
// @ts-expect-error
72+
render(h('div', null, [foo]), root)
73+
expect('Invalid VNode type').not.toHaveBeenWarned()
74+
expect(inner(root)).toBe('<div>[object Object]</div>')
75+
})
76+
6877
describe('renderer: keyed children', () => {
6978
let root: TestElement
7079
let elm: TestElement

‎packages/runtime-core/src/vnode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ export function normalizeVNode(child: VNodeChild): VNode {
793793
// #3666, avoid reference pollution when reusing vnode
794794
child.slice(),
795795
)
796-
} else if (typeof child === 'object') {
796+
} else if (isVNode(child)) {
797797
// already vnode, this should be the most common since compiled templates
798798
// always produce all-vnode children arrays
799799
return cloneIfMounted(child)

0 commit comments

Comments
 (0)
Please sign in to comment.