File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 7
7
h ,
8
8
nodeOps ,
9
9
toHandlers ,
10
- nextTick
10
+ nextTick ,
11
+ ref ,
12
+ watchEffect
11
13
} from '@vue/runtime-test'
12
14
import { isEmitListener } from '../src/componentEmits'
13
15
@@ -431,4 +433,36 @@ describe('component: emit', () => {
431
433
await nextTick ( )
432
434
expect ( fn ) . not . toHaveBeenCalled ( )
433
435
} )
436
+
437
+ test ( 'should not track during listener execution' , async ( ) => {
438
+ const counter = ref ( 0 )
439
+ const Comp = defineComponent ( {
440
+ emits : [ 'interaction' ] ,
441
+ setup ( props , { emit } ) {
442
+ const doEmit = ref ( true )
443
+ watchEffect ( ( ) => {
444
+ if ( doEmit . value ) emit ( 'interaction' )
445
+ } )
446
+ return ( ) => h ( 'div' )
447
+ }
448
+ } )
449
+ const el = nodeOps . createElement ( 'div' )
450
+ render (
451
+ h ( Comp , {
452
+ onInteraction : async ( ) => {
453
+ if ( counter . value < 5 ) {
454
+ await nextTick ( )
455
+ counter . value ++
456
+ }
457
+ }
458
+ } ) ,
459
+ el
460
+ )
461
+
462
+ await nextTick ( )
463
+ await nextTick ( )
464
+ await nextTick ( )
465
+
466
+ expect ( counter . value ) . toBe ( 1 )
467
+ } )
434
468
} )
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import {
27
27
compatModelEventPrefix ,
28
28
compatModelEmit
29
29
} from './compat/componentVModel'
30
+ import { pauseTracking , resetTracking } from '@vue/reactivity'
30
31
31
32
export type ObjectEmitsOptions = Record <
32
33
string ,
@@ -161,12 +162,14 @@ export function emit(
161
162
}
162
163
163
164
if ( handler ) {
165
+ pauseTracking ( )
164
166
callWithAsyncErrorHandling (
165
167
handler ,
166
168
instance ,
167
169
ErrorCodes . COMPONENT_EVENT_HANDLER ,
168
170
args
169
171
)
172
+ resetTracking ( )
170
173
}
171
174
172
175
const onceHandler = props [ handlerName + `Once` ]
You can’t perform that action at this time.
0 commit comments