]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): avoid rendering plain object as VNode (#12038)
authoredison <daiwei521@126.com>
Thu, 26 Sep 2024 09:08:48 +0000 (17:08 +0800)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2024 09:08:48 +0000 (17:08 +0800)
close #12035
close vitejs/vite-plugin-vue#353

packages/runtime-core/__tests__/rendererChildren.spec.ts
packages/runtime-core/src/vnode.ts

index 47024b674f4c44ef665b25874b8d2461f66cfb3b..2c3e5ff0d1a14ccd80dd0a81fab83f214df2f4e3 100644 (file)
@@ -65,6 +65,15 @@ test('array children -> text children', () => {
   expect(inner(root)).toBe('<div>hello</div>')
 })
 
+test('plain object child', () => {
+  const root = nodeOps.createElement('div')
+  const foo = { foo: '1' }
+  // @ts-expect-error
+  render(h('div', null, [foo]), root)
+  expect('Invalid VNode type').not.toHaveBeenWarned()
+  expect(inner(root)).toBe('<div>[object Object]</div>')
+})
+
 describe('renderer: keyed children', () => {
   let root: TestElement
   let elm: TestElement
index 57c0cf8b7d2242500efbe94372a6b7d8f2aae274..30200789be8f7bcefb13eb131e393ef0a0b886ce 100644 (file)
@@ -793,7 +793,7 @@ export function normalizeVNode(child: VNodeChild): VNode {
       // #3666, avoid reference pollution when reusing vnode
       child.slice(),
     )
-  } else if (typeof child === 'object') {
+  } else if (isVNode(child)) {
     // already vnode, this should be the most common since compiled templates
     // always produce all-vnode children arrays
     return cloneIfMounted(child)