fix(ivy): properly destroy views created by ComponentFactory (#27676)
PR Close #27676
This commit is contained in:
committed by
Miško Hevery
parent
f1c9d6a81f
commit
b00aeeff37
@@ -22,11 +22,10 @@ import {assertComponentType, assertDefined} from './assert';
|
||||
import {LifecycleHooksFeature, createRootComponent, createRootComponentView, createRootContext} from './component';
|
||||
import {getComponentDef} from './definition';
|
||||
import {NodeInjector} from './di';
|
||||
import {createLView, createNodeAtIndex, createTView, createViewNode, elementCreate, locateHostElement, refreshDescendantViews} from './instructions';
|
||||
import {addToViewTree, createLView, createNodeAtIndex, createTView, createViewNode, elementCreate, locateHostElement, refreshDescendantViews} from './instructions';
|
||||
import {ComponentDef, RenderFlags} from './interfaces/definition';
|
||||
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node';
|
||||
import {RElement, RendererFactory3, domRendererFactory3, isProceduralRenderer} from './interfaces/renderer';
|
||||
import {SanitizerFn} from './interfaces/sanitization';
|
||||
import {HEADER_OFFSET, LView, LViewFlags, RootContext, TVIEW} from './interfaces/view';
|
||||
import {enterView, leaveView} from './state';
|
||||
import {defaultScheduler, getTNode} from './util';
|
||||
@@ -169,6 +168,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
||||
|
||||
const componentView = createRootComponentView(
|
||||
hostRNode, this.componentDef, rootLView, rendererFactory, renderer);
|
||||
|
||||
tElementNode = getTNode(0, rootLView) as TElementNode;
|
||||
|
||||
// Transform the arrays of native nodes into a structure that can be consumed by the
|
||||
@@ -207,6 +207,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
||||
component = createRootComponent(
|
||||
componentView, this.componentDef, rootLView, rootContext, [LifecycleHooksFeature]);
|
||||
|
||||
addToViewTree(rootLView, HEADER_OFFSET, componentView);
|
||||
|
||||
refreshDescendantViews(rootLView, RenderFlags.Create);
|
||||
} finally {
|
||||
leaveView(oldLView, true);
|
||||
|
||||
@@ -455,16 +455,18 @@ export function getParentState(state: LView | LContainer, rootView: LView): LVie
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all listeners and call all onDestroys in a given view.
|
||||
* Calls onDestroys hooks for all directives and pipes in a given view and then removes all
|
||||
* listeners. Listeners are removed as the last step so events delivered in the onDestroys hooks
|
||||
* can be propagated to @Output listeners.
|
||||
*
|
||||
* @param view The LView to clean up
|
||||
*/
|
||||
function cleanUpView(viewOrContainer: LView | LContainer): void {
|
||||
if ((viewOrContainer as LView).length >= HEADER_OFFSET) {
|
||||
const view = viewOrContainer as LView;
|
||||
removeListeners(view);
|
||||
executeOnDestroys(view);
|
||||
executePipeOnDestroys(view);
|
||||
removeListeners(view);
|
||||
const hostTNode = view[HOST_NODE];
|
||||
// For component views only, the local renderer is destroyed as clean up time.
|
||||
if (hostTNode && hostTNode.type === TNodeType.Element && isProceduralRenderer(view[RENDERER])) {
|
||||
|
||||
Reference in New Issue
Block a user