Explorar el Código

fix(runtime-core): prevent merging model listener when value is null or undefined (#14629)

fix https://github.com/vuejs/ecosystem-ci/actions/runs/23529115737/job/68488818862
edison hace 4 semanas
padre
commit
b39e0329f6

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

@@ -477,6 +477,12 @@ describe('vnode', () => {
       expect(mergeProps({ onClick: null })).toMatchObject({
         onClick: null,
       })
+      expect(
+        mergeProps({ 'onUpdate:modelValue': undefined }),
+      ).not.toHaveProperty('onUpdate:modelValue')
+      expect(mergeProps({ 'onUpdate:modelValue': null })).not.toHaveProperty(
+        'onUpdate:modelValue',
+      )
     })
 
     test('default', () => {

+ 8 - 1
packages/runtime-core/src/vnode.ts

@@ -6,6 +6,7 @@ import {
   extend,
   isArray,
   isFunction,
+  isModelListener,
   isObject,
   isOn,
   isString,
@@ -891,7 +892,13 @@ export function mergeProps(...args: (Data & VNodeProps)[]): Data {
           ret[key] = existing
             ? [].concat(existing as any, incoming as any)
             : incoming
-        } else if (incoming == null && existing == null) {
+        } else if (
+          incoming == null &&
+          existing == null &&
+          // mergeProps({ 'onUpdate:modelValue': undefined }) should not retain
+          // the model listener.
+          !isModelListener(key)
+        ) {
           ret[key] = incoming
         }
       } else if (key !== '') {