]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core/vnode): should not render boolean values in vnode children (close...
authorEvan You <yyx990803@gmail.com>
Mon, 6 Jan 2020 16:57:19 +0000 (11:57 -0500)
committerEvan You <yyx990803@gmail.com>
Mon, 6 Jan 2020 16:57:19 +0000 (11:57 -0500)
packages/runtime-core/__tests__/vnode.spec.ts
packages/runtime-core/src/vnode.ts

index 934b095286585a6087e6a94d2ad613612f8f235a..656d27644b99f5726676181810e09c3fb1b89e77 100644 (file)
@@ -120,6 +120,12 @@ describe('vnode', () => {
     expect(normalizeVNode(null)).toMatchObject({ type: Comment })
     expect(normalizeVNode(undefined)).toMatchObject({ type: Comment })
 
+    // boolean -> Comment
+    // this is for usage like `someBoolean && h('div')` and behavior consistency
+    // with 2.x (#574)
+    expect(normalizeVNode(true)).toMatchObject({ type: Comment })
+    expect(normalizeVNode(false)).toMatchObject({ type: Comment })
+
     // array -> Fragment
     expect(normalizeVNode(['foo'])).toMatchObject({ type: Fragment })
 
@@ -137,7 +143,6 @@ describe('vnode', () => {
     // primitive types
     expect(normalizeVNode('foo')).toMatchObject({ type: Text, children: `foo` })
     expect(normalizeVNode(1)).toMatchObject({ type: Text, children: `1` })
-    expect(normalizeVNode(true)).toMatchObject({ type: Text, children: `true` })
   })
 
   test('type shapeFlag inference', () => {
index cab6ce8a99451ae0ef0644dbdeaf48cf5619cfca..1f08d5cab5b678da39274010cd046cb48b81f474 100644 (file)
@@ -337,7 +337,7 @@ export function createCommentVNode(
 }
 
 export function normalizeVNode<T, U>(child: VNodeChild<T, U>): VNode<T, U> {
-  if (child == null) {
+  if (child == null || typeof child === 'boolean') {
     // empty placeholder
     return createVNode(Comment)
   } else if (isArray(child)) {
@@ -348,7 +348,7 @@ export function normalizeVNode<T, U>(child: VNodeChild<T, U>): VNode<T, U> {
     // always produce all-vnode children arrays
     return child.el === null ? child : cloneVNode(child)
   } else {
-    // primitive types
+    // strings and numbers
     return createVNode(Text, null, String(child))
   }
 }