revert: fix(ivy): remove query results from destroyed embedded views (#28445)
This reverts commit 5ebc0da640
.
This commit is contained in:
parent
5ebc0da640
commit
22d3226491
|
@ -242,17 +242,14 @@ export function destroyViewTree(rootView: LView): void {
|
||||||
while (viewOrContainer) {
|
while (viewOrContainer) {
|
||||||
let next: LView|LContainer|null = null;
|
let next: LView|LContainer|null = null;
|
||||||
|
|
||||||
if (isLContainer(viewOrContainer)) {
|
if (viewOrContainer.length >= HEADER_OFFSET) {
|
||||||
// If container, traverse down to its first LView.
|
|
||||||
const container = viewOrContainer as LContainer;
|
|
||||||
const viewsInContainer = container[VIEWS];
|
|
||||||
if (viewsInContainer.length) {
|
|
||||||
next = viewsInContainer[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If LView, traverse down to child.
|
// If LView, traverse down to child.
|
||||||
const view = viewOrContainer as LView;
|
const view = viewOrContainer as LView;
|
||||||
if (view[TVIEW].childIndex > -1) next = getLViewChild(view);
|
if (view[TVIEW].childIndex > -1) next = getLViewChild(view);
|
||||||
|
} else {
|
||||||
|
// If container, traverse down to its first LView.
|
||||||
|
const container = viewOrContainer as LContainer;
|
||||||
|
if (container[VIEWS].length) next = container[VIEWS][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
|
@ -261,15 +258,6 @@ export function destroyViewTree(rootView: LView): void {
|
||||||
while (viewOrContainer && !viewOrContainer ![NEXT] && viewOrContainer !== rootView) {
|
while (viewOrContainer && !viewOrContainer ![NEXT] && viewOrContainer !== rootView) {
|
||||||
cleanUpView(viewOrContainer);
|
cleanUpView(viewOrContainer);
|
||||||
viewOrContainer = getParentState(viewOrContainer, rootView);
|
viewOrContainer = getParentState(viewOrContainer, rootView);
|
||||||
if (isLContainer(viewOrContainer)) {
|
|
||||||
// this view will be destroyed so we need to notify queries that a view is detached
|
|
||||||
const viewsInContainer = (viewOrContainer as LContainer)[VIEWS];
|
|
||||||
for (let viewToDetach of viewsInContainer) {
|
|
||||||
if (viewToDetach[QUERIES]) {
|
|
||||||
viewToDetach[QUERIES] !.removeView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cleanUpView(viewOrContainer || rootView);
|
cleanUpView(viewOrContainer || rootView);
|
||||||
next = viewOrContainer && viewOrContainer ![NEXT];
|
next = viewOrContainer && viewOrContainer ![NEXT];
|
||||||
|
|
|
@ -127,8 +127,7 @@ export function isComponentDef<T>(def: DirectiveDef<T>): def is ComponentDef<T>
|
||||||
return (def as ComponentDef<T>).template !== null;
|
return (def as ComponentDef<T>).template !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLContainer(
|
export function isLContainer(value: RElement | RComment | LContainer | StylingContext): boolean {
|
||||||
value: RElement | RComment | LContainer | LView | StylingContext | null): boolean {
|
|
||||||
// Styling contexts are also arrays, but their first index contains an element node
|
// Styling contexts are also arrays, but their first index contains an element node
|
||||||
return Array.isArray(value) && value.length === LCONTAINER_LENGTH;
|
return Array.isArray(value) && value.length === LCONTAINER_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
|
@ -633,24 +633,25 @@ describe('Query API', () => {
|
||||||
expect(q.query.map((d: TextDirective) => d.text)).toEqual(['2', '1']);
|
expect(q.query.map((d: TextDirective) => d.text)).toEqual(['2', '1']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove manually projected templates if their parent view is destroyed', () => {
|
fixmeIvy('FW-920: Queries in nested views are not destroyed properly')
|
||||||
const template = `
|
.it('should remove manually projected templates if their parent view is destroyed', () => {
|
||||||
|
const template = `
|
||||||
<manual-projecting #q><ng-template #tpl><div text="1"></div></ng-template></manual-projecting>
|
<manual-projecting #q><ng-template #tpl><div text="1"></div></ng-template></manual-projecting>
|
||||||
<div *ngIf="shouldShow">
|
<div *ngIf="shouldShow">
|
||||||
<ng-container [ngTemplateOutlet]="tpl"></ng-container>
|
<ng-container [ngTemplateOutlet]="tpl"></ng-container>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
const view = createTestCmp(MyComp0, template);
|
const view = createTestCmp(MyComp0, template);
|
||||||
const q = view.debugElement.children[0].references !['q'];
|
const q = view.debugElement.children[0].references !['q'];
|
||||||
view.componentInstance.shouldShow = true;
|
view.componentInstance.shouldShow = true;
|
||||||
view.detectChanges();
|
view.detectChanges();
|
||||||
|
|
||||||
expect(q.query.length).toBe(1);
|
expect(q.query.length).toBe(1);
|
||||||
|
|
||||||
view.componentInstance.shouldShow = false;
|
view.componentInstance.shouldShow = false;
|
||||||
view.detectChanges();
|
view.detectChanges();
|
||||||
expect(q.query.length).toBe(0);
|
expect(q.query.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
modifiedInIvy('https://github.com/angular/angular/issues/15117 fixed in ivy')
|
modifiedInIvy('https://github.com/angular/angular/issues/15117 fixed in ivy')
|
||||||
.it('should not throw if a content template is queried and created in the view during change detection',
|
.it('should not throw if a content template is queried and created in the view during change detection',
|
||||||
|
|
Loading…
Reference in New Issue