Skip to content

Commit b592d02

Browse files
fix(devtools): extensions in zone.js (#245) [backport v19]
Run the DevTools extensions connection outside of zone.js. Otherwise, the extensions would trigger zone.js unnecessarily every second. Closes #239
1 parent 406ebc8 commit b592d02

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

libs/ngrx-toolkit/src/lib/devtools/internal/devtools-syncer.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { isPlatformBrowser } from '@angular/common';
2-
import { inject, Injectable, OnDestroy, PLATFORM_ID } from '@angular/core';
2+
import {
3+
inject,
4+
Injectable,
5+
NgZone,
6+
OnDestroy,
7+
PLATFORM_ID,
8+
} from '@angular/core';
39
import { StateSource } from '@ngrx/signals';
410
import { REDUX_DEVTOOLS_CONFIG } from '../provide-devtools-config';
511
import { currentActionNames } from './current-action-names';
@@ -52,11 +58,13 @@ export class DevtoolsSyncer implements OnDestroy {
5258
#currentState: Record<string, object> = {};
5359
#currentId = 1;
5460

55-
readonly #connection: Connection = this.#isBrowser
56-
? window.__REDUX_DEVTOOLS_EXTENSION__
57-
? window.__REDUX_DEVTOOLS_EXTENSION__.connect(this.#devtoolsConfig)
58-
: dummyConnection
59-
: dummyConnection;
61+
readonly #connection: Connection = inject(NgZone).runOutsideAngular(() =>
62+
this.#isBrowser
63+
? window.__REDUX_DEVTOOLS_EXTENSION__
64+
? window.__REDUX_DEVTOOLS_EXTENSION__.connect(this.#devtoolsConfig)
65+
: dummyConnection
66+
: dummyConnection,
67+
);
6068

6169
constructor() {
6270
if (!this.#isBrowser) {

0 commit comments

Comments
 (0)