New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ivy): properly destroy view trees where root is an embedded view … #23482
fix(ivy): properly destroy view trees where root is an embedded view … #23482
Conversation
ea2e5e2
to
14dea45
Compare
You can preview ea2e5e2 at https://pr23482-ea2e5e2.ngbuilds.io/. |
You can preview 14dea45 at https://pr23482-14dea45.ngbuilds.io/. |
selectors: [['my-app']], | ||
// <button (click)="toggle()">Toggle List</button> | ||
// <ul> | ||
// <li *ngFor="let item of items">{{index}} of {{count}}: {{item}}</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment here is off from the actual liTemplate
template function, in which only {{item}}
is used as li's text content. Also, why not just include this in an @Component
annotation?
@@ -231,21 +231,24 @@ export function destroyViewTree(rootView: LView): void { | |||
next = viewOrContainer.views[0].data; | |||
} else if (viewOrContainer.child) { | |||
next = viewOrContainer.child; | |||
} else if (viewOrContainer.next) { | |||
} else if (viewOrContainer.next && viewOrContainer !== rootView) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to avoid adding this check and the one on line 251 if we return early for the case that the root view has no children. e.g.
function destroyViewTree(rootView: LView): void {
if (!rootView.child) return cleanUpView(rootView);
let viewOrContainer: LViewOrLContainer|null = rootView.child;
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, great 👍 - those repeated checks were not nice, this is much better! Amending the PR.
d034923
to
4132eae
Compare
Thnx for review @kara - amended the PR based on your suggestion. Please have another look / approve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// If the viewOrContainer is the rootView, then the cleanup is done twice. | ||
// Without this check, ngOnDestroy would be called twice for a directive on an element. | ||
// If the viewOrContainer is the rootView and next is null it means that we are dealing | ||
// with a root view that doesn't have children. We didn't descent into child views |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: descent -> descend
…without children The bug fixed here steams from the fact that we are traversing too far up in the views tree hierarchy in the destroyViewTree function. The logic in destroyViewTree is off if we start removal at an embedded view without any child views. For such a case we should just clean up (cleanUpView) this one view without paying attention to next / parent views.
4132eae
to
718c93d
Compare
You can preview 718c93d at https://pr23482-718c93d.ngbuilds.io/. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…without children
The bug fixed here steams from the fact that we are traversing too far up
in the views tree hierarchy in the destroyViewTree function.
The logic in destroyViewTree is off if we start removal at an embedded view
without any child views. For such a case we should just clean up (cleanUpView)
this one view without paying attention to next / parent views.
@kara I very much dislike how the solution in this PR keeps repeating
!== rootView
but didn't come up with anything better without fully understanding thedestroyViewTree
. Let's discuss more in the office