Skip to content
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

Conversation

pkozlowski-opensource
Copy link
Member

…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 the destroyViewTree. Let's discuss more in the office

@mary-poppins
Copy link

You can preview ea2e5e2 at https://pr23482-ea2e5e2.ngbuilds.io/.

@mary-poppins
Copy link

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>
Copy link
Member

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) {
Copy link
Contributor

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;
  ...
}

Copy link
Member Author

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.

@pkozlowski-opensource pkozlowski-opensource force-pushed the vcref_view_tree branch 2 times, most recently from d034923 to 4132eae Compare April 23, 2018 23:37
@pkozlowski-opensource pkozlowski-opensource added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 23, 2018
@pkozlowski-opensource
Copy link
Member Author

Thnx for review @kara - amended the PR based on your suggestion. Please have another look / approve.

Copy link
Contributor

@kara kara left a 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
Copy link
Contributor

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.
@pkozlowski-opensource pkozlowski-opensource removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 23, 2018
@kara
Copy link
Contributor

kara commented Apr 23, 2018

presubmit

@mary-poppins
Copy link

You can preview 718c93d at https://pr23482-718c93d.ngbuilds.io/.

@pkozlowski-opensource pkozlowski-opensource added the action: merge The PR is ready for merge by the caretaker label Apr 24, 2018
@vicb vicb closed this in b1d03fe Apr 24, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants