mirror of https://github.com/vuejs/core.git
fix(scheduler): recover nextTick from error in post flush cb
This commit is contained in:
parent
2b05c1e906
commit
2bbb6d2fc5
|
@ -844,4 +844,12 @@ describe('scheduler', () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(calls).toEqual(['cb2', 'cb1'])
|
expect(calls).toEqual(['cb2', 'cb1'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('error in postFlush cb should not cause nextTick to stuck in rejected state forever', async () => {
|
||||||
|
queuePostFlushCb(() => {
|
||||||
|
throw 'err'
|
||||||
|
})
|
||||||
|
await expect(nextTick).rejects.toThrow('err')
|
||||||
|
await expect(nextTick()).resolves.toBeUndefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -119,7 +119,10 @@ export function queueJob(job: SchedulerJob): void {
|
||||||
|
|
||||||
function queueFlush() {
|
function queueFlush() {
|
||||||
if (!currentFlushPromise) {
|
if (!currentFlushPromise) {
|
||||||
currentFlushPromise = resolvedPromise.then(flushJobs)
|
currentFlushPromise = resolvedPromise.then(flushJobs).catch(e => {
|
||||||
|
currentFlushPromise = null
|
||||||
|
throw e
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,9 +204,14 @@ export function flushPostFlushCbs(seen?: CountMap): void {
|
||||||
if (cb.flags! & SchedulerJobFlags.ALLOW_RECURSE) {
|
if (cb.flags! & SchedulerJobFlags.ALLOW_RECURSE) {
|
||||||
cb.flags! &= ~SchedulerJobFlags.QUEUED
|
cb.flags! &= ~SchedulerJobFlags.QUEUED
|
||||||
}
|
}
|
||||||
if (!(cb.flags! & SchedulerJobFlags.DISPOSED)) cb()
|
if (!(cb.flags! & SchedulerJobFlags.DISPOSED)) {
|
||||||
|
try {
|
||||||
|
cb()
|
||||||
|
} finally {
|
||||||
cb.flags! &= ~SchedulerJobFlags.QUEUED
|
cb.flags! &= ~SchedulerJobFlags.QUEUED
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
activePostFlushCbs = null
|
activePostFlushCbs = null
|
||||||
postFlushIndex = 0
|
postFlushIndex = 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue