Skip to content

Commit cd0e323

Browse files
committed
fix(runtime-core): avoid side effects when invoking emit handler
1 parent 163b365 commit cd0e323

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/runtime-core/src/componentEmits.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import type { ComponentTypeEmits } from './apiSetupHelpers'
3333
import { getModelModifiers } from './helpers/useModel'
3434
import type { ComponentPublicInstance } from './componentPublicInstance'
35+
import { pauseTracking, resetTracking } from '@vue/reactivity'
3536

3637
export type ObjectEmitsOptions = Record<
3738
string,
@@ -198,12 +199,14 @@ export function emit(
198199
}
199200

200201
if (handler) {
202+
pauseTracking()
201203
callWithAsyncErrorHandling(
202204
handler,
203205
instance,
204206
ErrorCodes.COMPONENT_EVENT_HANDLER,
205207
args,
206208
)
209+
resetTracking()
207210
}
208211

209212
const onceHandler = props[handlerName + `Once`]
@@ -214,12 +217,14 @@ export function emit(
214217
return
215218
}
216219
instance.emitted[handlerName] = true
220+
pauseTracking()
217221
callWithAsyncErrorHandling(
218222
onceHandler,
219223
instance,
220224
ErrorCodes.COMPONENT_EVENT_HANDLER,
221225
args,
222226
)
227+
resetTracking()
223228
}
224229

225230
if (__COMPAT__) {

0 commit comments

Comments
 (0)