Zoneless
Zoneless Architecture (stabilized in Angular 20 and enabled by default for new applications since Angular 21) removes Zone.js from Angular applications. Instead of monkey-patching browser APIs to guess when data might have changed, Angular now relies on explicit notifications—primarily Signals—to know exactly when and where to update the DOM.
In Angular 22, this evolution went a step further by making ChangeDetectionStrategy.OnPush the default for all components (renaming the legacy default strategy to Eager).
How Change Detection Evolved: Before vs. Now
| Feature | Before: Zone-Based (Zone.js) |
Now: Zoneless + Signals (v21 – v22+) |
|---|---|---|
| Trigger Mechanism | Zone.js monkey-patches setTimeout, Promise, fetch, and DOM events to notify Angular after every async task. |
Explicit notifications from Signals (.set(), .update()), template event listeners (click), async pipe, or markForCheck(). |
| Component Tree Check | Top-down check starting from the root component down to every child (Default / Eager). |
Targeted updates only to views where a read Signal actually changed. |
| Default Strategy | ChangeDetectionStrategy.Default (checks every component on every cycle). |
ChangeDetectionStrategy.OnPush (default since Angular 22; legacy behavior renamed to Eager). |
| Bundle & Runtime | Adds ~15 KB (gzipped) overhead for Zone.js, slows down startup, and produces noisy stack traces. |
Zero Zone.js dependency, faster initial rendering, cleaner debugging stack traces, and native async/await support. |
What Triggers UI Updates in Zoneless Angular?
Without Zone.js, Angular schedules change detection only when one of these specific events occurs:
- A Signal read in a template changes (via
signal(),computed(),input(), orresource()). - A template event listener fires (such as
(click)or(input)). - An Observable updates via the
asyncpipe (which callsmarkForCheck()internally). - Manual notification via
ChangeDetectorRef.markForCheck()(rarely needed in new signal code). - Component attachment or detachment (such as dynamic rendering or route changes).
Before vs. Now: Code Comparison
Consider a timer and background data polling component where state updates asynchronously inside setInterval or a Promise.
Before: Zone-Based Angular (Relied on Zone.js Magic)
In legacy Angular, mutating a plain class property inside setInterval or fetch().then() worked automatically because Zone.js intercepted the browser's timer and triggered a full application check.
import { Component, OnInit, OnDestroy } from '@angular/core';
@Component({
selector: 'app-legacy-dashboard',
// Implicitly used ChangeDetectionStrategy.Default (now called Eager)
template: `
<h3>Server Status: {{ status }}</h3>
<p>Uptime ticks: {{ seconds }}</p>
<button (click)="reset()">Reset</button>
`
})
export class LegacyDashboardComponent implements OnInit, OnDestroy {
// Plain class properties (not reactive)
status = 'Connecting...';
seconds = 0;
private timerId?: number;
ngOnInit() {
// Zone.js monkey-patched setInterval, forcing Angular to check
// the ENTIRE component tree every single second.
this.timerId = window.setInterval(() => {
this.seconds++;
}, 1000);
// Zone.js also patched Promise.then()
Promise.resolve('Online').then(res => {
this.status = res;
});
}
reset() {
this.seconds = 0;
}
ngOnDestroy() {
clearInterval(this.timerId);
}
}
Why this breaks in Zoneless: If you run the code above without Zone.js, this.seconds++ mutates the JavaScript variable in memory, but the DOM never updates because nothing notified Angular that seconds changed.
Now: Modern Zoneless Angular (Angular 21 – 22+)
In modern zoneless Angular, state is stored in Signals. When seconds.update() runs inside setInterval, the signal directly marks only the <p> text node dirty, scheduling a surgical render without checking unrelated components.
import { Component, signal, DestroyRef, inject } from '@angular/core';
@Component({
selector: 'app-zoneless-dashboard',
// ChangeDetectionStrategy.OnPush is the default in Angular 22+
template: `
<h3>Server Status: {{ status() }}</h3>
<p>Uptime ticks: {{ seconds() }}</p>
<button (click)="reset()">Reset</button>
`
})
export class ZonelessDashboardComponent {
private destroyRef = inject(DestroyRef);
// Reactive Signals notify Angular directly when mutated
status = signal('Connecting...');
seconds = signal(0);
constructor() {
// Native setInterval works without Zone.js because seconds.update() notifies Angular
const timerId = window.setInterval(() => {
this.seconds.update(s => s + 1);
}, 1000);
// Clean up automatically when the component destroys
this.destroyRef.onDestroy(() => clearInterval(timerId));
// Native async/await or Promises work without Zone.js monkey-patching
Promise.resolve('Online').then(res => {
this.status.set(res);
});
}
reset() {
this.seconds.set(0);
}
}
Bootstrapping a Zoneless App (app.config.ts)
- Angular 21 & 22+: New projects created with
ng neware zoneless by default (provideZonelessChangeDetection()is included automatically, andzone.jsis omitted frompackage.jsonandangular.json). - Upgrading Existing Apps (v18 – v20+): You opt in via
app.config.tsand removezone.jsfrom yourangular.jsonpolyfills:
import { ApplicationConfig, provideZonelessChangeDetection } from '@angular/core';
export const appConfig: ApplicationConfig = {
providers: [
// Enables zoneless scheduling (default in v21+)
provideZonelessChangeDetection()
]
};
Common Pitfalls When Migrating to Zoneless
- Mutating plain class variables in async callbacks. Any state displayed in the template that changes inside
setTimeout,setInterval, WebSockets, or third-party event listeners must be wrapped in asignal()(or converted viatoSignal()). - Mutating arrays/objects in place. Calling
this.items().push(newItem)does not trigger a signal notification; always usethis.items.update(list => [...list, newItem]). - Legacy components expecting
Eagerchecks. In Angular 22, if an unmigrated third-party or legacy component relies on mutating plain properties withoutOnPushcompatibility, you can temporarily setchangeDetection: ChangeDetectionStrategy.Eageron that specific component while refactoring it to Signals.
OnPush vs. Eager
In Angular 22, ChangeDetectionStrategy.OnPush became the default for all components, while the legacy "check always" strategy (ChangeDetectionStrategy.Default) was deprecated and renamed to ChangeDetectionStrategy.Eager.
Previously, developers had to manually add changeDetection: ChangeDetectionStrategy.OnPush to every component for optimal performance. Now, omitting changeDetection gives you OnPush automatically.
OnPush vs. Eager Comparison
| Feature | ChangeDetectionStrategy.OnPush (New Default) |
ChangeDetectionStrategy.Eager (Legacy Behavior) |
|---|---|---|
| How to Enable | Automatic when changeDetection is omitted. |
Must be explicitly set in @Component({ changeDetection: ChangeDetectionStrategy.Eager }). |
| Traversal Behavior | Skips the component and its subtree unless something inside it is explicitly marked dirty. | Checks the component and its subtree on every global change detection cycle. |
| What Triggers a Check | A read Signal updates, an @Input() / input() reference changes, a local template event fires, async pipe emits, or markForCheck() is called. |
Any application-wide activity (timers, network responses, clicks in sibling components, etc.). |
| State Requirement | Requires immutable updates or Signals so Angular can detect changes. | Works with plain mutable class properties (this.count++). |
| Status in v22+ | The standard, recommended strategy. | Compatibility escape hatch (Default is deprecated and slated for removal in v24). |
How They Behave in a Component Tree
Imagine an application tree: AppRoot → Sidebar → UserCard.
- With
Eager(Legacy "Check Always")
If a user clicks a button inside AppRoot (or a timer fires anywhere in the app), Angular walks down from AppRoot into Sidebar and UserCard—re-evaluating every template expression—even if nothing in Sidebar or UserCard changed.
- With
OnPush(Angular 22 Default)
When an event happens in AppRoot, Angular does not enter Sidebar or UserCard. It skips entire branches of the component tree unless:
- A Signal read in that component's template changes (e.g.,
user().name). - An input passed from the parent changes (a new object reference or updated signal input).
- A DOM event fires inside that component or one of its children (e.g.,
(click)="save()"). ChangeDetectorRef.markForCheck()is called manually (or via theasyncpipe).
Code Example: OnPush vs. Eager
Modern OnPush Component (No Decorator Property Needed)
Because OnPush is the default in Angular 22, you write clean components without extra configuration. Using Signals ensures the view updates reliably.
import { Component, signal, input } from '@angular/core';
@Component({
selector: 'app-loan-summary',
// Uses ChangeDetectionStrategy.OnPush automatically in Angular 22+
template: `
<h4>{{ title() }}</h4>
<span>Total: \${{ total() }}</span>
<button (click)="addFee()">Add $10 Fee</button>
`
})
export class LoanSummaryComponent {
title = input.required<string>();
total = signal(100);
addFee() {
// Updating a signal marks this component's view dirty and triggers an update
this.total.update(amount => amount + 10);
}
}
Legacy Eager Component (When Mutating Plain Properties)
If you have an older component that mutates plain class variables without Signals or immutable inputs, OnPush will not re-render the screen when that variable changes externally. Setting Eager preserves the old behavior:
import { Component, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'app-legacy-summary',
// Explicitly opts into the old "check always" behavior
changeDetection: ChangeDetectionStrategy.Eager,
template: `<span>Total: \${{ total }}</span>`
})
export class LegacySummaryComponent {
// Plain mutable property (not a Signal)
total = 100;
// If a parent component calls this method directly without changing an @Input,
// OnPush would miss the update, whereas Eager re-checks and updates the DOM.
updateTotal(newAmount: number) {
this.total = newAmount;
}
}
How ng update Migrates Existing Projects
When you upgrade an existing app to Angular 22 using ng update, the Angular CLI runs an automatic schematic to prevent existing apps from breaking:
- Components with no
changeDetectionset automatically havechangeDetection: ChangeDetectionStrategy.Eageradded to them. - Components using
ChangeDetectionStrategy.Defaultare renamed toChangeDetectionStrategy.Eager. - Components already using
ChangeDetectionStrategy.OnPushremain unchanged.
Practical Tip: Treat
ChangeDetectionStrategy.Eagerin your codebase as a refactoring to-do list. Once you convert a component's state to Signals and immutable inputs, you can simply delete thechangeDetection: ChangeDetectionStrategy.Eagerline so it falls back to Angular 22'sOnPushdefault.
References
- https://angular.dev/api/core/ChangeDetectionStrategy
- https://angular.dev/guide/components/advanced-configuration
- https://angular.love/angular-22-key-features-and-changes
- https://medium.com/@saneekadam1326/angular-22-just-changed-the-default-you-have-been-overriding-for-9-years-and-4-more-shifts-425848cd14dd
- https://www.linkedin.com/posts/sanket-bhor_angular-angular22-changedetection-activity-7469807463215853568-lU3D
- https://www.youtube.com/watch?v=6lF5xMBk1aA&t=47