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(scheduler): ensure recursive jobs can't be queued twice #11955

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

skirtles-code
Copy link
Contributor

This PR was originally going to be just tests for #11826, which was merged a couple of weeks ago. But while working on the tests I realised there was a small bug in my original PR, which I've fixed here.

In my original fix, I assumed that it was safe to clear the QUEUED flag unconditionally after a job had run. However, this isn't always correct for jobs with ALLOW_RECURSE.

For a job with ALLOW_RECURSE, the QUEUED flag is already cleared before the job runs. If the job does recurse then the QUEUED flag will be set again. In that scenario it shouldn't be cleared after the job runs. Mistakenly clearing the flag allows the job to be added to the queue again.

In practice, even if the job does get queued twice, the dirtiness checks should significantly limit its impact. The 'Maximum recursive updates' warning could be hit prematurely, but as the bug only allows the job to be queued twice it would still need to recurse several times to hit that warning.

While the bug is low impact, it's also an easy fix.

There is some duplication between flushJobs and flushPreFlushCbs. I may investigate refactoring that later, but I didn't want to complicate this PR with a refactoring.

The tests cover various scenarios for both this fix and the original fix in #11826.

This PR only considers the main scheduler queue, not the post queue. The post queue does still need tests writing for #11826, but there are various other edge cases I need to think through before I attempt that. It uses a Set to de-duplicate jobs, so it isn't impacted by the bug I've fixed here.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (+24 B) 37.9 kB (+3 B) 34.1 kB (-28 B)
vue.global.prod.js 159 kB (+24 B) 57.8 kB (+3 B) 51.3 kB (-64 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.8 kB (+24 B) 18.8 kB (+8 B) 17.2 kB (+12 B)
createApp 55.4 kB (+24 B) 21.3 kB (+8 B) 19.4 kB (+15 B)
createSSRApp 59.4 kB (+24 B) 23 kB (+5 B) 21 kB
defineCustomElement 60.2 kB (+24 B) 22.9 kB (+9 B) 20.8 kB (-48 B)
overall 69.1 kB (+24 B) 26.4 kB (+4 B) 24 kB (+1 B)

Copy link

pkg-pr-new bot commented Sep 18, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@11955

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@11955

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@11955

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@11955

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@11955

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@11955

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@11955

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@11955

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@11955

vue

pnpm add https://pkg.pr.new/vue@11955

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@11955

commit: a776c1a

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Sep 18, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt success success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros failure failure
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Sep 18, 2024
@yyx990803 yyx990803 merged commit d18d6aa into vuejs:main Sep 20, 2024
13 checks passed
yangmingshan added a commit to vue-mini/vue-mini that referenced this pull request Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants