@@ -11,7 +11,7 @@ import {attachPatchData} from './context_discovery';
11
11
import { callHooks } from './hooks' ;
12
12
import { LContainer , NATIVE , VIEWS , unusedValueExportToPlacateAjd as unused1 } from './interfaces/container' ;
13
13
import { ComponentDef } from './interfaces/definition' ;
14
- import { TContainerNode , TElementContainerNode , TElementNode , TNode , TNodeFlags , TNodeType , TProjectionNode , TViewNode , unusedValueExportToPlacateAjd as unused2 } from './interfaces/node' ;
14
+ import { TContainerNode , TElementContainerNode , TElementNode , TNode , TNodeFlags , TNodeType , TViewNode , unusedValueExportToPlacateAjd as unused2 } from './interfaces/node' ;
15
15
import { unusedValueExportToPlacateAjd as unused3 } from './interfaces/projection' ;
16
16
import { ProceduralRenderer3 , RComment , RElement , RNode , RText , Renderer3 , isProceduralRenderer , unusedValueExportToPlacateAjd as unused4 } from './interfaces/renderer' ;
17
17
import { CLEANUP , CONTAINER_INDEX , FLAGS , HEADER_OFFSET , HOST_NODE , HookData , LView , LViewFlags , NEXT , PARENT , QUERIES , RENDERER , TVIEW , unusedValueExportToPlacateAjd as unused5 } from './interfaces/view' ;
@@ -242,14 +242,17 @@ export function destroyViewTree(rootView: LView): void {
242
242
while ( viewOrContainer ) {
243
243
let next : LView | LContainer | null = null ;
244
244
245
- if ( viewOrContainer . length >= HEADER_OFFSET ) {
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 {
246
253
// If LView, traverse down to child.
247
254
const view = viewOrContainer as LView ;
248
255
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 ] ;
253
256
}
254
257
255
258
if ( next == null ) {
@@ -258,6 +261,15 @@ export function destroyViewTree(rootView: LView): void {
258
261
while ( viewOrContainer && ! viewOrContainer ! [ NEXT ] && viewOrContainer !== rootView ) {
259
262
cleanUpView ( viewOrContainer ) ;
260
263
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
+ }
261
273
}
262
274
cleanUpView ( viewOrContainer || rootView ) ;
263
275
next = viewOrContainer && viewOrContainer ! [ NEXT ] ;
0 commit comments