Skip to content

Commit adc3ad7

Browse files
committed
chore: trigger side effects after scheduled for watch() and render()
1 parent fa80d44 commit adc3ad7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/runtime-core/src/apiWatch.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ReactiveEffect,
77
isReactive,
88
ReactiveFlags,
9-
EffectScheduler,
109
DebuggerOptions,
1110
getCurrentScope
1211
} from '@vue/reactivity'
@@ -364,19 +363,22 @@ function doWatch(
364363
// it is allowed to self-trigger (#1727)
365364
job.allowRecurse = !!cb
366365

367-
let scheduler: EffectScheduler
366+
let schedulerJob: SchedulerJob
368367
if (flush === 'sync') {
369-
scheduler = onScheduled => onScheduled(job as any) // the scheduler function gets called directly
368+
schedulerJob = job // the scheduler function gets called directly
370369
} else if (flush === 'post') {
371-
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense)
370+
schedulerJob = () =>
371+
queuePostRenderEffect(job, instance && instance.suspense)
372372
} else {
373373
// default: 'pre'
374374
job.pre = true
375375
if (instance) job.id = instance.uid
376-
scheduler = () => queueJob(job)
376+
schedulerJob = () => queueJob(job)
377377
}
378378

379-
const effect = new ReactiveEffect(getter, scheduler)
379+
const effect = new ReactiveEffect(getter, onScheduled => {
380+
onScheduled(schedulerJob as any)
381+
})
380382

381383
const unwatch = () => {
382384
effect.stop()

packages/runtime-core/src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,10 @@ function baseCreateRenderer(
15451545
}
15461546

15471547
// create reactive effect for rendering
1548+
const schedulerJob = () => queueJob(update)
15481549
const effect = (instance.effect = new ReactiveEffect(
15491550
componentUpdateFn,
1550-
() => queueJob(update),
1551+
onScheduled => onScheduled(schedulerJob),
15511552
instance.scope // track it in component's effect scope
15521553
))
15531554

0 commit comments

Comments
 (0)