Skip to content

fix(core): order post watchers after render in flush - #13386

Open
shoemoney wants to merge 1 commit into
vuejs:mainfrom
shoemoney:fix/queuewatcher-post-order
Open

shoemoney wants to merge 1 commit into
vuejs:mainfrom
shoemoney:fix/queuewatcher-post-order

Conversation

@shoemoney

@shoemoney shoemoney commented Aug 26, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

Other information:

When queueWatcher is called during a flush, the new watcher is spliced into the queue by id only. A post watcher (flush: 'post') can therefore land before a render watcher with a higher id, which breaks the guarantee that render runs before post callbacks.

This PR replaces the id-only comparison in the insertion loop with sortCompareFn, which orders non-post watchers before post watchers and then by id. That matches the initial queue sort, so post watchers queued mid-flush run after render watchers.

Before: queue[i].id > watcher.id
After: sortCompareFn(queue[i], watcher) > 0

Verified red to green. The existing unit suite passes (1449 tests, scheduler.spec 8 tests).

Changed file: src/core/observer/scheduler.ts

Fix verified RED->GREEN. queueWatcher flush-post ordering broken: post watchers spliced by id only at scheduler.ts:183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant