]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): avoid side effects when invoking emit handler edison/fix/13338 13340/head
authordaiwei <daiwei521@126.com>
Fri, 16 May 2025 13:59:47 +0000 (21:59 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 16 May 2025 13:59:47 +0000 (21:59 +0800)
packages/runtime-core/src/componentEmits.ts

index db52bc88c333e02176c4da3409ea89177879250d..0014754d8b25ea984a99d093c5fa560925a55510 100644 (file)
@@ -32,6 +32,7 @@ import {
 import type { ComponentTypeEmits } from './apiSetupHelpers'
 import { getModelModifiers } from './helpers/useModel'
 import type { ComponentPublicInstance } from './componentPublicInstance'
+import { pauseTracking, resetTracking } from '@vue/reactivity'
 
 export type ObjectEmitsOptions = Record<
   string,
@@ -198,12 +199,14 @@ export function emit(
   }
 
   if (handler) {
+    pauseTracking()
     callWithAsyncErrorHandling(
       handler,
       instance,
       ErrorCodes.COMPONENT_EVENT_HANDLER,
       args,
     )
+    resetTracking()
   }
 
   const onceHandler = props[handlerName + `Once`]
@@ -214,12 +217,14 @@ export function emit(
       return
     }
     instance.emitted[handlerName] = true
+    pauseTracking()
     callWithAsyncErrorHandling(
       onceHandler,
       instance,
       ErrorCodes.COMPONENT_EVENT_HANDLER,
       args,
     )
+    resetTracking()
   }
 
   if (__COMPAT__) {