fix(ivy): restore global state after running refreshView (#32521)
Prior to this commit, the `previousOrParentTNode` was set to null after performing all operations within `refreshView` function. It's causing problems in more complex scenarios, for example when change detection is triggered during DI (see test added as a part of this commit). As a result, global state might be corrupted. This commit captures current value of `previousOrParentTNode` and restores it after `refreshView` call. PR Close #32521
This commit is contained in:

committed by
Matias Niemelä

parent
664e0015d4
commit
a1beba4b6e
@ -471,6 +471,8 @@ export function renderComponentOrTemplate<T>(
|
||||
const rendererFactory = hostView[RENDERER_FACTORY];
|
||||
const normalExecutionPath = !getCheckNoChangesMode();
|
||||
const creationModeIsActive = isCreationMode(hostView);
|
||||
const previousOrParentTNode = getPreviousOrParentTNode();
|
||||
const isParent = getIsParent();
|
||||
try {
|
||||
if (normalExecutionPath && !creationModeIsActive && rendererFactory.begin) {
|
||||
rendererFactory.begin();
|
||||
@ -484,6 +486,7 @@ export function renderComponentOrTemplate<T>(
|
||||
if (normalExecutionPath && !creationModeIsActive && rendererFactory.end) {
|
||||
rendererFactory.end();
|
||||
}
|
||||
setPreviousOrParentTNode(previousOrParentTNode, isParent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1642,6 +1645,8 @@ export function tickRootContext(rootContext: RootContext) {
|
||||
|
||||
export function detectChangesInternal<T>(view: LView, context: T) {
|
||||
const rendererFactory = view[RENDERER_FACTORY];
|
||||
const previousOrParentTNode = getPreviousOrParentTNode();
|
||||
const isParent = getIsParent();
|
||||
|
||||
if (rendererFactory.begin) rendererFactory.begin();
|
||||
try {
|
||||
@ -1652,6 +1657,7 @@ export function detectChangesInternal<T>(view: LView, context: T) {
|
||||
throw error;
|
||||
} finally {
|
||||
if (rendererFactory.end) rendererFactory.end();
|
||||
setPreviousOrParentTNode(previousOrParentTNode, isParent);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user