-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Add helper function for queuing state updates (#54224)
This adds a helper function to defer application state updates to the first possible "safe" moment. If application-wide change detection (ApplicationRef.tick) is currently executing when this function is used, the callback will execute as soon as all views attached to the `ApplicationRef` have been refreshed. Refreshing the application views will happen again before `checkNoChanges` executes. When a change detection is _not_ running, this state update will execute in the microtask queue. This function is necessary as a replacement for current `Promise.resolve().then(() => stateUpdate())` to be zoneless compatible while ensuring those state updates are synchronized to the DOM before the browser repaint. Without this, updates done in `Promise.resolve(...)` would queue another round of change detection in zoneless applications, and this change detection could happen in the next browser frame, and cause noticeable flicker for the user. Additionally, this function provides a way to perform state updates that will run on the server as well as in the browser. Last, current applications using `ngZone: 'noop'` may not be calling `ApplicationRef.tick` at all so this function provides a mechanism to ensure the state update still happens by racing a microtask with `afterNextRender` (which might never execute). PR Close #54224
- Loading branch information
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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