Let’s go Zoneless
Matthieu Riegler
Grenoble 🏔, France 🇫🇷
@jean_ _ meche
June 24th, 2024
@jean_ _meche
Matt
Jean Meche
Team / OSS
@jean_ _meche
Angular.dev
Is Zoneless
@jean_ _meche
Thank you !
Matthieu Riegler
Grenoble, France
@jean_ _ meche
@jean_ _meche
What are we talking about ?
@jean_ _meche
Zone.js is Angular’s scheduler
A question of
when
ApplicationRef.tick()
@jean_ _meche
Monkey Patching
Promise
setTimeout
setInterval
queueMicrotask
addEventListener
@jean_ _meche
30 kB - eagerly loaded
Zones, runtime context
Messy stacktrace
No support for native Async/Await
Downsides of zone.js
@jean_ _meche
Root component
component
component
component
component
component
component
component
component
component
component
component
component
ApplicationRef.tick()
@jean_ _meche
How do we do this
without Zone.js
@jean_ _meche
A new scheduler
A question of
when
setTimeout or requestAnimationFrame
@jean_ _meche
Enable Zoneless change detection
provideExperimentalZonelessChangeDetection
@jean_ _meche
Observable$ 👓
{{ myObs$ |async }}
@jean_ _meche
myStrSignal.set(‘someValue’)
myNumberSignal.update(v => v+1)
Signals 📡
@jean_ _meche
The framework 🅰️
(myEvent)=”myCallback($event)”
@jean_ _meche
What you need for zoneless
@jean_ _meche
Zone.js
Is more than just a scheduler
@jean_ _meche
Global state
A question of
Stability
@jean_ _meche
Server-side-rendering
💻
When stable
@jean_ _meche
Dom operations
this._ngZone.onStable(() => {
// some DOM operation
})
@jean_ _meche
after*Render
afterNextRender(() =>
// some DOM operation
})
afterRender(() =>
// some DOM operation
})
@jean_ _meche
PendingTasks
New global service
To handle stability
@jean_ _meche
PendingTasks
HttpRequests
Pending Effects
@jean_ _meche
New API !
const pendingTasks = inject(ExperimentalPendingTasks);
const taskCleanup = pendingTasks.add();
// do work that should block application's stability and then:
taskCleanup();
// Or also soon:
pendingTasks.run(async () => {
await myAsyncFunc();
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ExperimentalPendingTasks
Editor
Preview
Both
@jean_ _meche
New API !
someLongTask$.pipe(
pendingUntilEvent()
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pendingUntilEvent
Editor
Preview
Both
@jean_ _meche
Do I need OnPush with
Zoneless ?
@jean_ _meche
When vs What
Zoneless | OnPush |
When component are checked | What Component are checked |
@jean_ _meche
Thank you !
Matthieu Riegler
Grenoble, France
@jean_ _ meche
@jean_ _meche