feat(core): Mark components for check if they read a signal by atscott · Pull Request #49153 · angular/angular

@atscott added the target: major

This PR is targeted for the next major release

label

Feb 22, 2023

@atscott atscott marked this pull request as ready for review

February 23, 2023 00:55

phhien203

pkozlowski-opensource

pkozlowski-opensource

phhien203

alxhub

alxhub previously requested changes Feb 23, 2023

alxhub

@atscott atscott added action: merge

The PR is ready for merge by the caretaker

merge: caretaker note

Alert the caretaker performing the merge to check the PR for an out of normal action needed or note

and removed action: review

The PR is still awaiting reviews from at least one requested reviewer

labels

Mar 16, 2023
This commit updates the `LView` in Angular to be a `Consumer` of
signals. If a signal is read when executing a template, it marks the
view dirty. In addition, if a signal is read when executing host
bindings, it also marks views dirty.

One interesting thing about signal reads in host bindings
is that they perform a bit better than what we can do with today's
APIs. In order to re-execute host bindings for an `OnPush` component that
might have changed, you would probably inject `ChangeDetectorRef` and call
`markForCheck`. This will mark the _current component_ and parents
dirty. However, host bindings are executed as part of refreshing the
_parent_ so there is really no need to re-execute the current component
if the only thing that changed is the host bindings. When a signal is
read in host bindings, it marks the parent dirty and not the component
that defined the host binding.

Additionally, this commit avoids allocating a full consumer for each
`LView` by re-using a consumer until template execution results in a
signal read. At this point, we assign that consumer to the `LView` and
create a new consumer to "tentatively" use for the future `LView`
template executions.

Co-authored-by: Dylan Hunn <github@dylanhunn.com>

@atscott