From c35ec47d73212b1b1fb1abca9004f992c45aa942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Fri, 21 Jan 2022 07:13:29 +0100 Subject: [PATCH] fix(runtime-core): ensure mergeProps skips undefined event handlers (#5299) fix #5296 --- packages/runtime-core/__tests__/vnode.spec.ts | 4 ++++ packages/runtime-core/src/vnode.ts | 1 + packages/runtime-dom/src/modules/events.ts | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index a8979e81..fdd23797 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -446,6 +446,10 @@ describe('vnode', () => { onClick: [clickHandler1, clickHandler2], onFocus: focusHandler2 }) + let props3: Data = { onClick: undefined } + expect(mergeProps(props1, props3)).toMatchObject({ + onClick: clickHandler1 + }) }) test('default', () => { diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 0db4005c..059d8ba3 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -798,6 +798,7 @@ export function mergeProps(...args: (Data & VNodeProps)[]) { const existing = ret[key] const incoming = toMerge[key] if ( + incoming && existing !== incoming && !(isArray(existing) && existing.includes(incoming)) ) { diff --git a/packages/runtime-dom/src/modules/events.ts b/packages/runtime-dom/src/modules/events.ts index 7172e3ef..51544ded 100644 --- a/packages/runtime-dom/src/modules/events.ts +++ b/packages/runtime-dom/src/modules/events.ts @@ -141,7 +141,7 @@ function patchStopImmediatePropagation( originalStop.call(e) ;(e as any)._stopped = true } - return value.map(fn => (e: Event) => !(e as any)._stopped && fn(e)) + return value.map(fn => (e: Event) => !(e as any)._stopped && fn && fn(e)) } else { return value }