I have migrated my app to zoneless thanks to provideExperimentalZonelessChangeDetection()
and having a mix of signals and Observables +AsyncPipe
.
Do I still need the OnPush
ChangeDetection Strategy ?
Components using the OnPush
change detection strategy, will be checked by change detection if the parent was checkd and if either:
- the component was marked dirty (via
markForCheck
/AsyncPipe
) - One of the input reference changed
- If an event listener in the template fires
We can say the OnPush
decides what componement will be checked by CD.
Angular apps also need to decide when the tick is fired from the ApplicationRef
. This is what we call scheduling. When is CD actually starting ?
In Zone apps, Zone.js is the scheduler by the means of patching all the async APIs (setTimout, Promise, addEventListener etc). So when one of those is called, a CD is scheduled.
In zoneless apps, this is no longer possible, no APIs are monkey patched. The framework needs to find another way to schedule CD. Today it uses following :
- Signal updates (
set
orupdate()
) - markForCheck() or
AsyncPipe
- If an event listener in the template fires
So to sum-up :
- Zoneless scheduling is about when components are checked
- OnPush is about what component is checked
Also to make things clear, OnPush is not the default when using Zoneless scheduling.