Skip to content

Comments

fix(core): Microtask scheduling should be used after any application synchronization#65885

Merged
AndrewKushnir merged 1 commit intoangular:mainfrom
atscott:microtaskschedulingontick
Dec 16, 2025
Merged

fix(core): Microtask scheduling should be used after any application synchronization#65885
AndrewKushnir merged 1 commit intoangular:mainfrom
atscott:microtaskschedulingontick

Conversation

@atscott
Copy link
Contributor

@atscott atscott commented Dec 5, 2025

Previously, Angular would switch from the macrotask to a microtask scheduler only when the scheduler was the trigger for the synchronization. This microtask scheduling is to ensure patterns such as Promise.resolve().then(() => updateAppStateAgain()) during synchronization are caught and synchronized again within the same event loop (guaranteeing that they aren't split across multiple browser paints).

The microtask scheduler should be used after any tick, not just from those than run within the scheduler to always account for the promises within synchronization. This is encountered most frequently during bootstrap, which triggers the tick directly.

In this change we exempt TestBed.tick and
ComponentFixture.detectChanges from this behavior. Doing so would affect the timing of stability and tests are quite sensitive to this (e.g. fixture.whenStable). It is somewhat unfortunate that we have "special" test-only behavior. However, it is important to acknowledge that this only affects the test-only APIs as well. Any code in the application under test that triggers ApplicationRef.tick directly would still use the microtask scheduling behavior.

fixes #65444

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Dec 5, 2025
@ngbot ngbot bot added this to the Backlog milestone Dec 5, 2025
@atscott atscott force-pushed the microtaskschedulingontick branch from dfecd83 to 3868d37 Compare December 5, 2025 20:26
@atscott atscott marked this pull request as ready for review December 10, 2025 00:00
@atscott atscott added the target: patch This PR is targeted for the next patch release label Dec 10, 2025
@atscott atscott requested a review from alxhub December 10, 2025 00:09
@atscott atscott force-pushed the microtaskschedulingontick branch from 3868d37 to a4916d8 Compare December 10, 2025 19:29
…synchronization

Previously, Angular would switch from the macrotask to a microtask
scheduler _only_ when the scheduler was the trigger for the
synchronization. This microtask scheduling is to ensure patterns such as
`Promise.resolve().then(() => updateAppStateAgain())` _during_
synchronization are caught and synchronized again within the same event
loop (guaranteeing that they aren't split across multiple browser paints).

The microtask scheduler should be used after any tick, not just from
those than run within the scheduler to always account for the promises
within synchronization. This is encountered most frequently during
bootstrap, which triggers the tick directly.

In this change we exempt `TestBed.tick` and
`ComponentFixture.detectChanges` from this behavior. Doing so would affect
the timing of stability and tests are quite sensitive to this (e.g.
`fixture.whenStable`). It is somewhat unfortunate that we have "special" test-only
behavior. However, it is important to acknowledge that this only affects
the test-only APIs as well. Any code in the application under test that
triggers `ApplicationRef.tick` directly would still use the microtask
scheduling behavior.

fixes angular#65444
@atscott atscott force-pushed the microtaskschedulingontick branch from a4916d8 to 87c9958 Compare December 10, 2025 20:25
@atscott atscott added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Dec 16, 2025
@AndrewKushnir AndrewKushnir merged commit 06be803 into angular:main Dec 16, 2025
20 of 22 checks passed
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: input flickers on initial load when using [ngModel]="true" (Angular 21) (zoneless)

3 participants