@@ -46,26 +46,7 @@ export function detectChangesInternal<T>(
4646
4747 try {
4848 refreshView ( tView , lView , tView . template , context ) ;
49- let retries = 0 ;
50- // If after running change detection, this view still needs to be refreshed or there are
51- // descendants views that need to be refreshed due to re-dirtying during the change detection
52- // run, detect changes on the view again. We run change detection in `Targeted` mode to only
53- // refresh views with the `RefreshView` flag.
54- while ( lView [ FLAGS ] & ( LViewFlags . RefreshView | LViewFlags . HasChildViewsToRefresh ) ||
55- lView [ REACTIVE_TEMPLATE_CONSUMER ] ?. dirty ) {
56- if ( retries === MAXIMUM_REFRESH_RERUNS ) {
57- throw new RuntimeError (
58- RuntimeErrorCode . INFINITE_CHANGE_DETECTION ,
59- ngDevMode &&
60- 'Infinite change detection while trying to refresh views. ' +
61- 'There may be components which each cause the other to require a refresh, ' +
62- 'causing an infinite loop.' ) ;
63- }
64- retries ++ ;
65- // Even if this view is detached, we still detect changes in targeted mode because this was
66- // the root of the change detection run.
67- detectChangesInView ( lView , ChangeDetectionMode . Targeted ) ;
68- }
49+ detectChangesInViewWhileDirty ( lView ) ;
6950 } catch ( error ) {
7051 if ( notifyErrorHandler ) {
7152 handleError ( lView , error ) ;
@@ -85,6 +66,29 @@ export function detectChangesInternal<T>(
8566 }
8667}
8768
69+ function detectChangesInViewWhileDirty ( lView : LView ) {
70+ let retries = 0 ;
71+ // If after running change detection, this view still needs to be refreshed or there are
72+ // descendants views that need to be refreshed due to re-dirtying during the change detection
73+ // run, detect changes on the view again. We run change detection in `Targeted` mode to only
74+ // refresh views with the `RefreshView` flag.
75+ while ( lView [ FLAGS ] & ( LViewFlags . RefreshView | LViewFlags . HasChildViewsToRefresh ) ||
76+ lView [ REACTIVE_TEMPLATE_CONSUMER ] ?. dirty ) {
77+ if ( retries === MAXIMUM_REFRESH_RERUNS ) {
78+ throw new RuntimeError (
79+ RuntimeErrorCode . INFINITE_CHANGE_DETECTION ,
80+ ngDevMode &&
81+ 'Infinite change detection while trying to refresh views. ' +
82+ 'There may be components which each cause the other to require a refresh, ' +
83+ 'causing an infinite loop.' ) ;
84+ }
85+ retries ++ ;
86+ // Even if this view is detached, we still detect changes in targeted mode because this was
87+ // the root of the change detection run.
88+ detectChangesInView ( lView , ChangeDetectionMode . Targeted ) ;
89+ }
90+ }
91+
8892export function checkNoChangesInternal < T > (
8993 tView : TView , lView : LView , context : T , notifyErrorHandler = true ) {
9094 setIsInCheckNoChangesMode ( true ) ;
0 commit comments