fix(core): Microtask scheduling should be used after any application synchronization#65885
Merged
AndrewKushnir merged 1 commit intoangular:mainfrom Dec 16, 2025
Merged
Conversation
dfecd83 to
3868d37
Compare
3868d37 to
a4916d8
Compare
…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
a4916d8 to
87c9958
Compare
alxhub
approved these changes
Dec 16, 2025
Contributor
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tickandComponentFixture.detectChangesfrom 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 triggersApplicationRef.tickdirectly would still use the microtask scheduling behavior.fixes #65444