fix(watch): fix flush: pre watchers triggered synchronously in setup
fix #5721
This commit is contained in:
@@ -345,15 +345,7 @@ function doWatch(
|
||||
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense)
|
||||
} else {
|
||||
// default: 'pre'
|
||||
scheduler = () => {
|
||||
if (!instance || instance.isMounted) {
|
||||
queuePreFlushCb(job)
|
||||
} else {
|
||||
// with 'pre' option, the first call must happen before
|
||||
// the component is mounted so it is called synchronously.
|
||||
job()
|
||||
}
|
||||
}
|
||||
scheduler = () => queuePreFlushCb(job)
|
||||
}
|
||||
|
||||
const effect = new ReactiveEffect(getter, scheduler)
|
||||
|
||||
@@ -182,6 +182,8 @@ export function flushPreFlushCbs(
|
||||
}
|
||||
|
||||
export function flushPostFlushCbs(seen?: CountMap) {
|
||||
// flush any pre cbs queued during the flush (e.g. pre watchers)
|
||||
flushPreFlushCbs()
|
||||
if (pendingPostFlushCbs.length) {
|
||||
const deduped = [...new Set(pendingPostFlushCbs)]
|
||||
pendingPostFlushCbs.length = 0
|
||||
|
||||
Reference in New Issue
Block a user