11import { DOCUMENT } from '@angular/common' ;
2- import { ElementRef , InjectionToken , Injector , Optional , SkipSelf , effect , runInInjectionContext } from '@angular/core' ;
2+ import {
3+ ChangeDetectorRef ,
4+ ElementRef ,
5+ InjectionToken ,
6+ Injector ,
7+ Optional ,
8+ SkipSelf ,
9+ effect ,
10+ inject ,
11+ runInInjectionContext ,
12+ } from '@angular/core' ;
313import { Subject , type Observable } from 'rxjs' ;
414import * as THREE from 'three' ;
515import type { NgtCamera , NgtDomEvent , NgtEventManager , NgtPointerCaptureTarget , NgtThreeEvent } from './events' ;
@@ -8,6 +18,7 @@ import { NGT_LOOP, type NgtLoop } from './loop';
818import { createInjectionToken } from './utils/create-injection-token' ;
919import { is } from './utils/is' ;
1020import { makeDpr } from './utils/make' ;
21+ import { safeDetectChanges } from './utils/safe-detect-changes' ;
1122import { signalStore , type NgtSignalStore } from './utils/signal-store' ;
1223import { updateCamera } from './utils/update' ;
1324
@@ -152,6 +163,8 @@ function storeFactory(loop: NgtLoop, document: Document, injector: Injector, par
152163 throw new Error ( `[NGT] Window is not available.` ) ;
153164 }
154165
166+ const cdr = inject ( ChangeDetectorRef ) ;
167+
155168 // NOTE: using Subject because we do not care about late-subscribers
156169 const pointerMissed$ = new Subject < MouseEvent > ( ) ;
157170
@@ -225,11 +238,12 @@ function storeFactory(loop: NgtLoop, document: Document, injector: Injector, par
225238 // Set lower bound performance
226239 if ( state . performance . current !== state . performance . min )
227240 setPerformanceCurrent ( state . performance . min ) ;
241+
228242 // Go back to upper bound performance after a while unless something regresses meanwhile
229- performanceTimeout = setTimeout (
230- ( ) => setPerformanceCurrent ( get ( 'performance' , 'max' ) ) ,
231- state . performance . debounce ,
232- ) ;
243+ performanceTimeout = setTimeout ( ( ) => {
244+ setPerformanceCurrent ( get ( 'performance' , 'max' ) ) ;
245+ safeDetectChanges ( cdr ) ;
246+ } , state . performance . debounce ) ;
233247 } ,
234248 } ,
235249
0 commit comments