Skip to content

fix(animations): cleanup DOM elements when the root view is removed#39982

Closed
arturovt wants to merge 1 commit intoangular:masterfrom
arturovt:fix/39955
Closed

fix(animations): cleanup DOM elements when the root view is removed#39982
arturovt wants to merge 1 commit intoangular:masterfrom
arturovt:fix/39955

Conversation

@arturovt
Copy link
Contributor

@arturovt arturovt commented Dec 5, 2020

Currently, when importing BrowserAnimationsModule, Angular uses AnimationRenderer
as the renderer. When the root view is removed, the AnimationRenderer defers the actual
work to the TransitionAnimationEngine to do this, and the TransitionAnimationEngine
doesn't actually remove the DOM node, but just calls markElementAsRemoved().

The actual DOM node is not removed until TransitionAnimationEngine "flushes".

Unfortunately, though, that "flush" will never happen, since the root view is being
destroyed and there will be no more flushes.

This commit adds flush() call when the root view is being destroyed.

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Issue Number: #39955

Does this PR introduce a breaking change?

  • Yes
  • No

@google-cla google-cla bot added the cla: yes label Dec 5, 2020
@pullapprove pullapprove bot requested review from atscott and crisbeto December 5, 2020 00:23
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one nit in the test.

@atscott atscott added area: animations area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release labels Dec 8, 2020
@ngbot ngbot bot modified the milestone: Backlog Dec 8, 2020
@atscott atscott added the area: testing Issues related to Angular testing features, such as TestBed label Dec 8, 2020
@atscott
Copy link
Contributor

atscott commented Dec 8, 2020

presubmit

@atscott
Copy link
Contributor

atscott commented Dec 8, 2020

Looks like this is causing some failures internally based on the presubmits and will need more investigation.

@atscott atscott added the action: presubmit The PR is in need of a google3 presubmit label Dec 8, 2020
Currently, when importing `BrowserAnimationsModule`, Angular uses `AnimationRenderer`
as the renderer. When the root view is removed, the `AnimationRenderer` defers the actual
work to the `TransitionAnimationEngine` to do this, and the `TransitionAnimationEngine`
doesn't actually remove the DOM node, but just calls `markElementAsRemoved()`.

The actual DOM node is not removed until `TransitionAnimationEngine` "flushes".

Unfortunately, though, that "flush" will never happen, since the root view is being
destroyed and there will be no more flushes.

This commit adds `flush()` call when the root view is being destroyed.

PR Close #39955
@arturovt
Copy link
Contributor Author

arturovt commented Dec 9, 2020

@atscott I have removed lifecycle hook from test. Ping me if some change is needed regarding the presubmit, since I can’t see why it fails

@pullapprove pullapprove bot removed area: animations area: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed labels Dec 9, 2020
@ngbot ngbot bot removed this from the Backlog milestone Dec 9, 2020
@ngbot ngbot bot added this to the Backlog milestone Dec 9, 2020
@ngbot ngbot bot removed this from the Backlog milestone Dec 9, 2020
@pullapprove pullapprove bot added area: animations area: core Issues related to the framework runtime labels Dec 10, 2020
@ngbot ngbot bot modified the milestone: Backlog Dec 10, 2020
@atscott
Copy link
Contributor

atscott commented Dec 29, 2020

@arturovt There were a couple instances of tests that were inadvertently depending on previous tests which had not been cleaned up. I've gone through and fixed these by hand, but we may still want to include this as a breaking change in v12 rather than in a minor/patch version.

@josephperrott is working on another project that has to do with test teardowns. Joey, I mentioned this PR to you before and you asked why this would cause failures because tests should be using the NoopAnimationsModule. This provider is actually still used by the NoopAnimationsModule because it's part of the SHARED_ANIMATION_PROVIDERS list:

{provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations'}, ...SHARED_ANIMATION_PROVIDERS
Would you mind taking over the review for this PR and rolling it into your "Tear Down Test Module/Environment After Each Test" project if that's the appropriate action here? For reference, here are the CLs that were required with this change: cl/349442306, cl/349440575
Edit: Also a link to the global tap run

@atscott atscott removed the target: patch This PR is targeted for the next patch release label Dec 29, 2020
@arturovt
Copy link
Contributor Author

@atscott I've also investigated that there is currently a memory leak on the server-side because engine doesn't flush elements on destroy:

image

This flush() call on destroy also fixes this issue.

@atscott
Copy link
Contributor

atscott commented Feb 10, 2021

Thanks for the additional info @arturovt. This is on our list to land for v12. Since it's a breaking change, we have to wait for a major release before merging.

@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 Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: presubmit The PR is in need of a google3 presubmit area: animations area: core Issues related to the framework runtime breaking changes cla: yes state: blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants