]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): class and style should be properly normalized in cloneVNode (...
authorHcySunYang <HcySunYang@outlook.com>
Wed, 26 Aug 2020 13:37:28 +0000 (21:37 +0800)
committerGitHub <noreply@github.com>
Wed, 26 Aug 2020 13:37:28 +0000 (09:37 -0400)
fix #1964

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

index 2cab3215d40bc24bc7b92a3b4b7eb50a85ac9655..ad3575610a92dc11e725f924649899087717153c 100644 (file)
@@ -265,6 +265,56 @@ describe('vnode', () => {
     setCurrentRenderingInstance(null)
   })
 
+  test('cloneVNode class normalization', () => {
+    const vnode = createVNode('div')
+    const expectedProps = {
+      class: 'a b'
+    }
+    expect(cloneVNode(vnode, { class: 'a b' }).props).toMatchObject(
+      expectedProps
+    )
+    expect(cloneVNode(vnode, { class: ['a', 'b'] }).props).toMatchObject(
+      expectedProps
+    )
+    expect(
+      cloneVNode(vnode, { class: { a: true, b: true } }).props
+    ).toMatchObject(expectedProps)
+    expect(
+      cloneVNode(vnode, { class: [{ a: true, b: true }] }).props
+    ).toMatchObject(expectedProps)
+  })
+
+  test('cloneVNode style normalization', () => {
+    const vnode = createVNode('div')
+    const expectedProps = {
+      style: {
+        color: 'blue',
+        width: '300px'
+      }
+    }
+    expect(
+      cloneVNode(vnode, { style: 'color: blue; width: 300px;' }).props
+    ).toMatchObject(expectedProps)
+    expect(
+      cloneVNode(vnode, {
+        style: {
+          color: 'blue',
+          width: '300px'
+        }
+      }).props
+    ).toMatchObject(expectedProps)
+    expect(
+      cloneVNode(vnode, {
+        style: [
+          {
+            color: 'blue',
+            width: '300px'
+          }
+        ]
+      }).props
+    ).toMatchObject(expectedProps)
+  })
+
   describe('mergeProps', () => {
     test('class', () => {
       let props1: Data = { class: 'c' }
index b444215ca26ef6c51dc2534d2987b798f2b7d796..0f20a534675d5a9a6fec180d6ccb7af4eb05ea06 100644 (file)
@@ -433,11 +433,7 @@ export function cloneVNode<T, U>(
   // This is intentionally NOT using spread or extend to avoid the runtime
   // key enumeration cost.
   const { props, patchFlag } = vnode
-  const mergedProps = extraProps
-    ? props
-      ? mergeProps(props, extraProps)
-      : extend({}, extraProps)
-    : props
+  const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props
   return {
     __v_isVNode: true,
     [ReactiveFlags.SKIP]: true,