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(animations): cleanup DOM elements when the root view is removed #45143

Closed
wants to merge 1 commit into from

Conversation

arturovt
Copy link
Contributor

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Issue Number: #45108

@JoostK
Copy link
Member

JoostK commented Feb 23, 2022

Judging by the commit description, would this issue be resolved if InjectableAnimationEngine were to inject ApplicationRef to force dependency ordering? I feel very uneasy to spawn asynchronous cleanup actions from within ngOnDestroy, as this kind of violates lifecycle expectations where the class is in a destroyed state and shouldn't be interacted with anymore.

@arturovt
Copy link
Contributor Author

arturovt commented Feb 23, 2022

Judging by the commit description, would this issue be resolved if InjectableAnimationEngine were to inject ApplicationRef to force dependency ordering? I feel very uneasy to spawn asynchronous cleanup actions from within ngOnDestroy, as this kind of violates lifecycle expectations where the class is in a destroyed state and shouldn't be interacted with anymore.

Yeah, that sounds more reasonable than my implementation.

@JoostK JoostK added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Feb 23, 2022
@jessicajaniuk jessicajaniuk added area: animations target: patch This PR is targeted for the next patch release labels Feb 24, 2022
@ngbot ngbot bot modified the milestone: Backlog Feb 24, 2022
@arturovt
Copy link
Contributor Author

@JoostK I've tried injecting ApplicationRef into animation engine and I'm getting Circular dependency in DI detected for ApplicationRef. This is because ApplicationRef depends on ApplicationInitStatus, the ApplicationInitStatus injects APP_INITIALIZER, which may have deps: [...] that depend on AnimationEngine. Any ideas?

@JoostK
Copy link
Member

JoostK commented Feb 24, 2022

Ah, I was afraid that might happen. One possibility could be to remove ApplicationInitStatus from the constructor and retrieve it lazily using the Injector, which is already stored in ApplicationRef in the _injector field.

@arturovt
Copy link
Contributor Author

@JoostK I've made updates, the CI is green. The only failing job seems to be unrelated to the change (not sure why it's failing).

@JoostK JoostK added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Mar 10, 2022
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I have added @jessicajaniuk as reviewer as I'm not a code owner for these parts of the FW, but I did leave some suggestions to clarify the tests.

jessicajaniuk
jessicajaniuk previously approved these changes Mar 10, 2022
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

LGTM 🍪

This seems good. I've left one minor suggestion and I'm also curious about your answers to @JoostK's questions.

@JoostK
Copy link
Member

JoostK commented Mar 10, 2022

About the breaking changes note: we generally don't consider constructors to be part of the public API so we may be able to land this in patch, but I'm also okay with just targeting major (v14) to be certain that we won't break people.

@JoostK JoostK added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 11, 2022
@AndrewKushnir AndrewKushnir removed action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit labels Mar 22, 2022
@AndrewKushnir AndrewKushnir self-assigned this Mar 22, 2022
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Mar 22, 2022

Sorry for the late reply. I've looked at the change and I think this solution might be incompatible with the new bootstrap API that we plan to introduce to support Standalone Components (there will be a public RFC about those APIs soon), more specifically, the ApplicationRef will likely be created sooner during the bootstrap process, so it would break implemented ordering. We can look into this issue once again and try to come up with a more explicit way to fix it, once the bootstrap API for standalone components is implemented (I'll keep you updated).

@arturovt
Copy link
Contributor Author

Hey @AndrewKushnir . I've rebased this PR on the main branch. This seems like tests are green with the new bootstrap API for standalone components. Are you able to run presubmit if those changes make sense?

@AndrewKushnir AndrewKushnir added action: global presubmit The PR is in need of a google3 global presubmit and removed state: blocked labels Jun 21, 2022
@AndrewKushnir
Copy link
Contributor

Global Presubmit (internal-only link).

Currently, when importing `BrowserAnimationsModule`, Angular provides
`AnimationRendererFactory` as the `RendererFactory2`. The `AnimationRendererFactory`
relies on the `AnimationEngine`. The `AnimationEngine` may be created earlier than the
`ApplicationRef` (e.g. if it's requested within the `APP_INITIALIZER` before the `ApplicationRef`
is created). This means that Angular will add the `AnimationEngine` to `R3Injector.onDestroy`
before the `ApplicationRef`. The `R3Injector` will call `ngOnDestroy()` on the `AnimationEngine`
before the `ApplicationRef`, which means the `flush()` will be called earlier before views are destroyed.

PR Close angular#45108
@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: global presubmit The PR is in need of a google3 global presubmit labels Jun 22, 2022
@jessicajaniuk jessicajaniuk removed the request for review from alxhub June 22, 2022 21:18
@dylhunn
Copy link
Contributor

dylhunn commented Jun 23, 2022

This PR was merged into the repository by commit 4eb1ca1.

dylhunn pushed a commit that referenced this pull request Jun 23, 2022
…45143)

Currently, when importing `BrowserAnimationsModule`, Angular provides
`AnimationRendererFactory` as the `RendererFactory2`. The `AnimationRendererFactory`
relies on the `AnimationEngine`. The `AnimationEngine` may be created earlier than the
`ApplicationRef` (e.g. if it's requested within the `APP_INITIALIZER` before the `ApplicationRef`
is created). This means that Angular will add the `AnimationEngine` to `R3Injector.onDestroy`
before the `ApplicationRef`. The `R3Injector` will call `ngOnDestroy()` on the `AnimationEngine`
before the `ApplicationRef`, which means the `flush()` will be called earlier before views are destroyed.

PR Close #45108

PR Close #45143
@dylhunn dylhunn closed this in 4eb1ca1 Jun 23, 2022
@arturovt arturovt deleted the fix/45108 branch June 23, 2022 21:03
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jul 4, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fanimations/14.0.3/14.0.4) |
| [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fcommon/14.0.3/14.0.4) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/14.0.3/14.0.4) |
| [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/14.0.3/14.0.4) |
| [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fcore/14.0.3/14.0.4) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fforms/14.0.3/14.0.4) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/14.0.3/14.0.4) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`14.0.3` -> `14.0.4`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/14.0.3/14.0.4) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v14.0.4`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1404-2022-06-29)

[Compare Source](angular/angular@14.0.3...14.0.4)

##### animations

| Commit | Type | Description |
| -- | -- | -- |
| [51be9bbe29](angular/angular@51be9bb) | fix | cleanup DOM elements when the root view is removed ([#&#8203;45143](angular/angular#45143)) |
| [999aca86c8](angular/angular@999aca8) | fix | enable shadowElements to leave when their parent does ([#&#8203;46459](angular/angular#46459)) |

##### common

| Commit | Type | Description |
| -- | -- | -- |
| [42aed6b13e](angular/angular@42aed6b) | fix | handle CSS custom properties in NgStyle ([#&#8203;46451](angular/angular#46451)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [1e7f22f00a](angular/angular@1e7f22f) | fix | trigger `ApplicationRef.destroy` when Platform is destroyed ([#&#8203;46497](angular/angular#46497)) |
| [8bde2dbc71](angular/angular@8bde2db) | fix | Update ngfor error code to be negative ([#&#8203;46555](angular/angular#46555)) |
| [57e8fc00eb](angular/angular@57e8fc0) | fix | Updates error to use RuntimeError code ([#&#8203;46526](angular/angular#46526)) |

##### forms

| Commit | Type | Description |
| -- | -- | -- |
| [74a26d870e](angular/angular@74a26d8) | fix | Convert existing reactive errors to use RuntimeErrorCode. ([#&#8203;46560](angular/angular#46560)) |
| [747872212d](angular/angular@7478722) | fix | Update a Forms validator error to use RuntimeError ([#&#8203;46537](angular/angular#46537)) |

##### router

| Commit | Type | Description |
| -- | -- | -- |
| [d6fac9e914](angular/angular@d6fac9e) | fix | Ensure that new `RouterOutlet` instances work after old ones are destroyed ([#&#8203;46554](angular/angular#46554)) |

#### Special Thanks

Alan Agius, Alex Rickabaugh, Andrew Kushnir, Andrew Scott, Bezael, Chad Ramos, Chellappan, Cédric Exbrayat, Dylan Hunn, George Kalpakas, Jeremy Meiss, Jessica Janiuk, Joey Perrott, KMathy, Kristiyan Kostadinov, Paul Gschwendtner, Pawel Kozlowski, Ramesh Thiruchelvam, Vaibhav Kumar, arturovt, dario-piotrowicz and renovate\[bot]

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1437
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@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 Jul 24, 2022
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 area: animations target: patch This PR is targeted for the next patch release
Projects
None yet
5 participants