fix(ivy): markForCheck() should not schedule change detection (#28048)
Previously, we had the logic to schedule a change detection tick inside markViewDirty(). This is fine when used in markDirty(), the user-facing API, because it should always schedule change detection. However, this doesn't work when used in markForCheck() because historically markForCheck() does not trigger change detection. To be backwards compatible, this commit moves the scheduling logic out of markViewDirty() and into markDirty(), so markForCheck no longer triggers a tick. PR Close #28048
This commit is contained in:

committed by
Andrew Kushnir

parent
feebe03523
commit
ad6569c744
@ -2376,17 +2376,24 @@ function wrapListenerWithPreventDefault(listenerFn: (e?: any) => any): EventList
|
||||
};
|
||||
}
|
||||
|
||||
/** Marks current view and all ancestors dirty */
|
||||
export function markViewDirty(lView: LView): void {
|
||||
/**
|
||||
* Marks current view and all ancestors dirty.
|
||||
*
|
||||
* Returns the root view because it is found as a byproduct of marking the view tree
|
||||
* dirty, and can be used by methods that consume markViewDirty() to easily schedule
|
||||
* change detection. Otherwise, such methods would need to traverse up the view tree
|
||||
* an additional time to get the root view and schedule a tick on it.
|
||||
*
|
||||
* @param lView The starting LView to mark dirty
|
||||
* @returns the root LView
|
||||
*/
|
||||
export function markViewDirty(lView: LView): LView {
|
||||
while (lView && !(lView[FLAGS] & LViewFlags.IsRoot)) {
|
||||
lView[FLAGS] |= LViewFlags.Dirty;
|
||||
lView = lView[PARENT] !;
|
||||
}
|
||||
lView[FLAGS] |= LViewFlags.Dirty;
|
||||
ngDevMode && assertDefined(lView[CONTEXT], 'rootContext should be defined');
|
||||
|
||||
const rootContext = lView[CONTEXT] as RootContext;
|
||||
scheduleTick(rootContext, RootContextFlags.DetectChanges);
|
||||
return lView;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2575,7 +2582,10 @@ function updateViewQuery<T>(viewQuery: ComponentQuery<{}>| null, view: LView, co
|
||||
*/
|
||||
export function markDirty<T>(component: T) {
|
||||
ngDevMode && assertDefined(component, 'component');
|
||||
markViewDirty(getComponentViewByInstance(component));
|
||||
const rootView = markViewDirty(getComponentViewByInstance(component));
|
||||
|
||||
ngDevMode && assertDefined(rootView[CONTEXT], 'rootContext should be defined');
|
||||
scheduleTick(rootView[CONTEXT] as RootContext, RootContextFlags.DetectChanges);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
Reference in New Issue
Block a user