Ver Fonte

fix(shared): ensure invokeArrayFns handles undefined arguments (#10869)

Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>

Close #10863
Tycho há 1 ano atrás
pai
commit
9b40d0f25d

+ 2 - 0
packages/runtime-core/__tests__/apiLifecycle.spec.ts

@@ -40,6 +40,8 @@ describe('api: lifecycle hooks', () => {
     }
     render(h(Comp), root)
     expect(fn).toHaveBeenCalledTimes(1)
+    // #10863
+    expect(fn).toHaveBeenCalledWith()
   })
 
   it('onMounted', () => {

+ 2 - 2
packages/shared/src/general.ts

@@ -133,9 +133,9 @@ export const toHandlerKey = cacheStringFunction(<T extends string>(str: T) => {
 export const hasChanged = (value: any, oldValue: any): boolean =>
   !Object.is(value, oldValue)
 
-export const invokeArrayFns = (fns: Function[], arg?: any) => {
+export const invokeArrayFns = (fns: Function[], ...arg: any[]) => {
   for (let i = 0; i < fns.length; i++) {
-    fns[i](arg)
+    fns[i](...arg)
   }
 }