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): allow animations on elements in the shadow DOM #40134

Closed

Conversation

jeripeierSBB
Copy link
Contributor

@jeripeierSBB jeripeierSBB commented Dec 15, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #25672

What is the new behavior?

enhanced containsElement method to not only use the native node contains method but to walk up the DOM tree by also considering shadow elements. Fixing this allows animations to be played if they are placed inside a shadow DOM.

Does this PR introduce a breaking change?

  • Yes
  • No

@google-cla google-cla bot added the cla: yes label Dec 15, 2020
@jeripeierSBB jeripeierSBB force-pushed the support-shadow-dom-animations branch 4 times, most recently from 2a7bea7 to bfe9555 Compare December 17, 2020 09:48
@jeripeierSBB jeripeierSBB marked this pull request as ready for review December 17, 2020 10:14
@pullapprove pullapprove bot requested a review from IgorMinar December 17, 2020 10:14
@ngbot ngbot bot added this to the Backlog milestone Dec 17, 2020
@LinboLen
Copy link

LinboLen commented Feb 24, 2021

ping... , does this pull request can be merged soon?. animation with ng-content or shadowdom won't work for a while .

@IonelLupu
Copy link

hey. How can we help with this PR? Maybe we can have it in the next Angular release. It's blocking some other animation related issues

@petebacondarwin petebacondarwin self-assigned this Mar 23, 2021
@petebacondarwin petebacondarwin self-requested a review March 23, 2021 13:34
@petebacondarwin
Copy link
Member

I am aware that I have still not reviewed this PR. I will prioritise it for next week.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

OK, so I finally got round to taking a look at this PR.
Thank you @jeripeierSBB for putting this together, and for your patience, everyone.
I think it is in pretty good shape. Just a couple of suggestions.

Also, since the commit message will appear in the CHANGELOG, can we reword it slightly...

fix(animations): allow animations on elements in the shadow DOM

When determining whether to run an animation, the `TransiationAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes #25672

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Apr 6, 2021
@jeripeierSBB
Copy link
Contributor Author

@petebacondarwin thanks a lot for your review. I will update the PR in the next days.

@jeripeierSBB jeripeierSBB force-pushed the support-shadow-dom-animations branch from 3afe416 to e0bb3b1 Compare April 7, 2021 07:04
@pullapprove pullapprove bot requested a review from alxhub April 7, 2021 07:04
@jeripeierSBB jeripeierSBB force-pushed the support-shadow-dom-animations branch from e0bb3b1 to f9b783d Compare April 7, 2021 07:37
@jeripeierSBB jeripeierSBB changed the title fix(animations): allow animations in shadow DOM fix(animations): allow animations on elements in the shadow DOM Apr 7, 2021
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @jeripeierSBB

Reviewed-for: size-tracking

We will need to get further reviews

goldens/size-tracking/aio-payloads.json Outdated Show resolved Hide resolved
@@ -21,7 +21,7 @@
"master": {
"uncompressed": {
"runtime-es2015": 3153,
"main-es2015": 437306,
"main-es2015": 437924,
Copy link
Member

Choose a reason for hiding this comment

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

Actual size on master was 437712. So this only adds 212 bytes.

Copy link
Member

Choose a reason for hiding this comment

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

Similarly this one can be 437844.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I did not really get the size tracking thing.. Thanks for pointing me in the right direction ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petebacondarwin I tried several ways to locally get the right size to enter here, but failed. What is the correct way to get the bundle file size which should be entered here (not waiting for ci to fail)?

@petebacondarwin petebacondarwin added action: presubmit The PR is in need of a google3 presubmit 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 Apr 7, 2021
@pullapprove pullapprove bot requested review from alxhub and atscott April 9, 2021 13:41
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.

Reviewed-for: size-tracking

When determining whether to run an animation, the `TransitionAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes angular#25672
When determining whether to run an animation, the `TransitionAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes angular#25672
When determining whether to run an animation, the `TransitionAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes angular#25672
When determining whether to run an animation, the `TransitionAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes angular#25672
@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 13, 2021
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Apr 13, 2021

Presubmit + Global Presubmit.

@AndrewKushnir AndrewKushnir removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Apr 13, 2021
@AndrewKushnir
Copy link
Contributor

@petebacondarwin FYI, presubmits (including the global one) are successful for the changes in this PR.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Apr 14, 2021
@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label Apr 14, 2021
@petebacondarwin
Copy link
Member

Thanks @AndrewKushnir - let's merge it!

@AndrewKushnir AndrewKushnir added target: rc This PR is targeted for the next release-candidate and removed target: patch This PR is targeted for the next patch release labels Apr 15, 2021
AndrewKushnir pushed a commit that referenced this pull request Apr 15, 2021
When determining whether to run an animation, the `TransitionAnimationPlayer`
checks to see if a DOM element is attached to the document. This is done by
checking to see if the element is "contained" by the document body node.

Previously, if the element was inside a shadow DOM, the engine would
determine that the element was not attached, even if the shadow DOM's
host was attached to the document. This commit updates the `containsElement()`
method on `AnimationDriver` implementations to also include shadow DOM
elements as being contained if their shadow host element is contained.

Further, when using CSS keyframes to trigger animations, the styling
was always added to the `head` element of the document, even for
animations on elements within a shadow DOM. This meant that those
elements never receive those styles and the animation would not run.
This commit updates the insertion of these styles so that they are added,
to the element's "root node", which is the nearest shadow DOM host, or the
`head` of the document if the element is not in a shadow DOM.

Closes #25672

PR Close #40134
@AndrewKushnir
Copy link
Contributor

FYI, this change was merged into the master and 12.0.x (RC) branches, but there was a conflict while merging into 11.2.x branch. If the change should also be included into the 11.2.x branch, please create a new PR targeting 11.2.x branch. Thank you.

@lubos-bistak
Copy link

Is it possible to apply this fix also to Angular 9?

@petebacondarwin
Copy link
Member

Since v9 is in LTS, it will not receive this bug fix, sorry.

@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 May 23, 2021
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 cla: yes target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants