You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(core): Add a warning when ApplicationRef.isStable doesn't emit true (#50295)
Hydration requires a stable App to run some logic.
With this warning developers will be informed about potential issues encountered when running an unstable app.
Fixes#50285
PR Close#50295
@shortDescription NgZone remains unstable after a long period of time
4
+
5
+
@description
6
+
This warning occurs when hydration is enabled on the client but the NgZone remains unstable for a long period of time.
7
+
8
+
The {@link ApplicationRef#isStable} API uses NgZone to report when an application becomes `stable` and `unstable`. An application is considered stable when there are no pending microtasks or macrotasks.
9
+
10
+
Angular Hydration relies on a signal from Zone.js when it becomes stable inside an application:
11
+
12
+
* during the server-side rendering (SSR) to start the serialization process
13
+
* in a browser this signal is used to start the post-hydration cleanup to remove DOM nodes that remained unclaimed
14
+
15
+
This warning is displayed when the `ApplicationRef.isStable()` doesn't emit `true` within 10 seconds. If this is intentional and your application becomes stable later, you can ignore this warning.
16
+
17
+
**Macrotasks**
18
+
19
+
Macrotasks include functions like `setInterval`, `setTimeout`, `requestAnimationFrame` etc.
20
+
If one of these functions is called in the initialization phase of the app or the bootstrapped components, the application will remain unstable.
21
+
22
+
```typescript
23
+
@Component({
24
+
standalone: true,
25
+
selector: 'app',
26
+
template: ``,
27
+
})
28
+
classSimpleComponent {
29
+
constructor() {
30
+
setInterval(() => { ... }, 1000)
31
+
32
+
// or
33
+
34
+
setTimeout(() => { ... }, 10_000)
35
+
}
36
+
}
37
+
```
38
+
39
+
If these functions need to be called in the initialization phase, invoking them outside the angular zone solves the issue.
40
+
41
+
```typescript
42
+
classSimpleComponent {
43
+
constructor() {
44
+
inject(NgZone).runOutsideAngular(() => {
45
+
setInterval(() => {}, 1000);
46
+
})
47
+
}
48
+
}
49
+
```
50
+
51
+
@debugging
52
+
53
+
Verify that you don't have any long standing microtask or macrotasks.
0 commit comments