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 ?
Yes.
Just as with zone-based change detection, it prevents your components from being checked if it's not needed, and thus increases the performance of each CD.
Components using the OnPush
change detection strategy will be checked by change detection if the parent was checked and if either:
markForCheck()
/AsyncPipe
)We can say the OnPush
strategy decides which component 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 (setTimeout()
, Promise, addEventListener()
, etc). When one of those is called, a CD is scheduled.
In zoneless apps, this is no longer possible as no APIs are monkey patched. The framework needs to find another way to schedule CD. Today it uses following:
set()
or update()
)markForCheck()
or AsyncPipe
To sum-up:
OnPush
is about which component is checkedAlso to make things clear, OnPush
is not the default when using Zoneless scheduling.