Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): schedulerJob skip correctly #2834

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/runtime-core/__tests__/scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,24 @@ describe('scheduler', () => {
}
const job3 = () => {
calls.push('job3')
invalidateJob(job1)
}
const job4 = () => {
calls.push('job4')
}
const job5 = () => {
calls.push('job5')
}
// queue all jobs
queueJob(job1)
queueJob(job2)
queueJob(job3)
queuePostFlushCb(job4)
queueJob(job4)
queuePostFlushCb(job5)
expect(calls).toEqual([])
await nextTick()
// job2 should be called only once
expect(calls).toEqual(['job1', 'job2', 'job3', 'job4'])
expect(calls).toEqual(['job1', 'job2', 'job3', 'job4', 'job5'])
})

test('sort job based on id', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function queueFlush() {

export function invalidateJob(job: SchedulerJob) {
const i = queue.indexOf(job)
if (i > -1) {
// skip job if it's not flush yet
if (i > flushIndex) {
queue.splice(i, 1)
}
}
Expand Down