refactor(core): Omit listeners from out-of-zone scheduling when using… #55525
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.
… ZoneJS (#55492)
In Angular today, a bound listener automatically marks the view for check. When using ZoneJS, these listeners are most often executed in the Angular Zone as well, so synchronization (
ApplicationRef.tick
) will eventually happen. However, developers can opt out of zone-patching for events in several ways, and often do this for very frequent listeners likemousemove
,resize
, andscroll
. We do not want to break existing expectations that these are now "safe" events to have listeners for by automatically scheduling change detection regardless of whether the listener executed inside or outside the Angular zone.In contrast, in order for developers to more easily transition to zoneless, we need to be able to ensure that components which are using
OnPush
are, for the most part, compatible with zoneless as well. Because listeners automatically mark the component for check, developers usingOnPush
did not/do not need to also callChangeDetectorRef.markForCheck
or a similar API. Unfortunately, this means that we need to consider the listener callbacks as a notification to schedule atick
when Zoneless is enabled. In the future, we would like to have an opt-out for this (i.e. signal components) since it's not really how we want things to work.Also includes the fix for #54919 that got reverted only because it was easier to revert the set of conflicting commits