Explorar o código

fix(runtime-core): avoid side effects when invoking emit handler

daiwei hai 11 meses
pai
achega
cd0e323fbe
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      packages/runtime-core/src/componentEmits.ts

+ 5 - 0
packages/runtime-core/src/componentEmits.ts

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