2
0
Эх сурвалжийг харах

fix(runtime-core): preserve nullish event handlers in mergeProps (#14550)

zhiyuanzmj 1 сар өмнө
parent
commit
5725222a6b

+ 5 - 0
packages/runtime-core/__tests__/vnode.spec.ts

@@ -472,6 +472,11 @@ describe('vnode', () => {
       expect(mergeProps(props1, props3)).toMatchObject({
         onClick: clickHandler1,
       })
+      const props4: Data = { onClick: undefined }
+      expect(mergeProps(props4)).toHaveProperty('onClick', undefined)
+      expect(mergeProps({ onClick: null })).toMatchObject({
+        onClick: null,
+      })
     })
 
     test('default', () => {

+ 2 - 0
packages/runtime-core/src/vnode.ts

@@ -891,6 +891,8 @@ export function mergeProps(...args: (Data & VNodeProps)[]): Data {
           ret[key] = existing
             ? [].concat(existing as any, incoming as any)
             : incoming
+        } else if (incoming == null && existing == null) {
+          ret[key] = incoming
         }
       } else if (key !== '') {
         ret[key] = toMerge[key]