Skip to content

Commit 22d3226

Browse files
committed
revert: fix(ivy): remove query results from destroyed embedded views (angular#28445)
This reverts commit 5ebc0da.
1 parent 5ebc0da commit 22d3226

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

packages/core/src/render3/node_manipulation.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,14 @@ export function destroyViewTree(rootView: LView): void {
242242
while (viewOrContainer) {
243243
let next: LView|LContainer|null = null;
244244

245-
if (isLContainer(viewOrContainer)) {
246-
// If container, traverse down to its first LView.
247-
const container = viewOrContainer as LContainer;
248-
const viewsInContainer = container[VIEWS];
249-
if (viewsInContainer.length) {
250-
next = viewsInContainer[0];
251-
}
252-
} else {
245+
if (viewOrContainer.length >= HEADER_OFFSET) {
253246
// If LView, traverse down to child.
254247
const view = viewOrContainer as LView;
255248
if (view[TVIEW].childIndex > -1) next = getLViewChild(view);
249+
} else {
250+
// If container, traverse down to its first LView.
251+
const container = viewOrContainer as LContainer;
252+
if (container[VIEWS].length) next = container[VIEWS][0];
256253
}
257254

258255
if (next == null) {
@@ -261,15 +258,6 @@ export function destroyViewTree(rootView: LView): void {
261258
while (viewOrContainer && !viewOrContainer ![NEXT] && viewOrContainer !== rootView) {
262259
cleanUpView(viewOrContainer);
263260
viewOrContainer = getParentState(viewOrContainer, rootView);
264-
if (isLContainer(viewOrContainer)) {
265-
// this view will be destroyed so we need to notify queries that a view is detached
266-
const viewsInContainer = (viewOrContainer as LContainer)[VIEWS];
267-
for (let viewToDetach of viewsInContainer) {
268-
if (viewToDetach[QUERIES]) {
269-
viewToDetach[QUERIES] !.removeView();
270-
}
271-
}
272-
}
273261
}
274262
cleanUpView(viewOrContainer || rootView);
275263
next = viewOrContainer && viewOrContainer ![NEXT];

packages/core/src/render3/util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ export function isComponentDef<T>(def: DirectiveDef<T>): def is ComponentDef<T>
127127
return (def as ComponentDef<T>).template !== null;
128128
}
129129

130-
export function isLContainer(
131-
value: RElement | RComment | LContainer | LView | StylingContext | null): boolean {
130+
export function isLContainer(value: RElement | RComment | LContainer | StylingContext): boolean {
132131
// Styling contexts are also arrays, but their first index contains an element node
133132
return Array.isArray(value) && value.length === LCONTAINER_LENGTH;
134133
}

packages/core/test/linker/query_integration_spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -633,24 +633,25 @@ describe('Query API', () => {
633633
expect(q.query.map((d: TextDirective) => d.text)).toEqual(['2', '1']);
634634
});
635635

636-
it('should remove manually projected templates if their parent view is destroyed', () => {
637-
const template = `
636+
fixmeIvy('FW-920: Queries in nested views are not destroyed properly')
637+
.it('should remove manually projected templates if their parent view is destroyed', () => {
638+
const template = `
638639
<manual-projecting #q><ng-template #tpl><div text="1"></div></ng-template></manual-projecting>
639640
<div *ngIf="shouldShow">
640641
<ng-container [ngTemplateOutlet]="tpl"></ng-container>
641642
</div>
642643
`;
643-
const view = createTestCmp(MyComp0, template);
644-
const q = view.debugElement.children[0].references !['q'];
645-
view.componentInstance.shouldShow = true;
646-
view.detectChanges();
644+
const view = createTestCmp(MyComp0, template);
645+
const q = view.debugElement.children[0].references !['q'];
646+
view.componentInstance.shouldShow = true;
647+
view.detectChanges();
647648

648-
expect(q.query.length).toBe(1);
649+
expect(q.query.length).toBe(1);
649650

650-
view.componentInstance.shouldShow = false;
651-
view.detectChanges();
652-
expect(q.query.length).toBe(0);
653-
});
651+
view.componentInstance.shouldShow = false;
652+
view.detectChanges();
653+
expect(q.query.length).toBe(0);
654+
});
654655

655656
modifiedInIvy('https://github.com/angular/angular/issues/15117 fixed in ivy')
656657
.it('should not throw if a content template is queried and created in the view during change detection',

0 commit comments

Comments
 (0)