fix(animations): allow enter animation of every inserted element#44243
fix(animations): allow enter animation of every inserted element#44243dario-piotrowicz wants to merge 1 commit into
Conversation
e8fdf5d to
d3d5b43
Compare
d3d5b43 to
a88bf99
Compare
There was a problem hiding this comment.
The comment should be self explanatory, but yeah, it seems like i18n insertions were done via insertBefore so they needed not to be treated as entering, since now everything is treated as entering the i18n insertions are no difference, I guess this should be ok 🤔
There was a problem hiding this comment.
Did you intend to say "threated"? Or did you mean threaded?
There was a problem hiding this comment.
"treated" 😅
honestly I just wanted to remove this test and not x-it, I just put the comment in the code to start a discussion
(seems like a succeeded, even though this is not the sort of discussion I was expecting 😆)
There was a problem hiding this comment.
my changes are only fixing the :enter issue, the :leave one can be treated separately (of if you want I can look into it and add it to this PR)
There was a problem hiding this comment.
my changes are only fixing the :enter issue, the :leave one can be treated separately (of if you want I can look into it and add it to this PR)
currently in the animations package not all newly inserted elements are treated as entering ones, thus querying them via ':enter' does not always work as expeted, change such behavior so that all newly inserted elements are considered entering ones solves: angular#30477
a88bf99 to
87475d7
Compare
jessicajaniuk
left a comment
There was a problem hiding this comment.
LGTM 🍪
Other than that one spelling error this looks good.
There was a problem hiding this comment.
Did you intend to say "threated"? Or did you mean threaded?
JoostK
left a comment
There was a problem hiding this comment.
Drive-by-comment about one change in particular; I have not attempted to understand the problem nor the approach taken by this PR (and that would likely require significant time as the animations logic is 🤯)
| } | ||
| } | ||
|
|
||
| function addClassRecursively(element: any, className: string) { |
There was a problem hiding this comment.
I am concerned about this approach for perf reasons; adding and removing classes is not free. Would it be possible to tweak query selectors from .${class} to something like .${class}, .${class} * to select all descendants? I am not sure about the perf characteristics of such query, though.
There was a problem hiding this comment.
Yes I understand what you mean....
I don't think that tweaking the selector should be too much of an issue
For context the code that does the querying is this one:
angular/packages/animations/browser/src/dsl/animation_timeline_builder.ts
Lines 563 to 588 in 155742e
I think that before selector = selector.replace(ENTER_TOKEN_REGEX, '.' + this._enterClassName); we could have a check and if the element doing the querying is entering then we just substitute the assignment to: selector = selector.replace(ENTER_TOKEN_REGEX, '*');
(ps: there is not info about the parent element entering so we would need to add that somehow too)
this seems like a pretty inexpensive change
Then what actually actually does the querying (called by the driver._query above) is a simple querySelector/querySelectorAll:
angular/packages/animations/browser/src/render/shared.ts
Lines 192 to 214 in 8d0511d
this again doesn't seem like a too expensive change since we use the browser's native api... I think?! 🤷
what do you think? does this sound like a good thing to try out? shall I give it a shot?
|
Thanks so very much for the reviewing all 🙂 In the issue's thread (#30477) we've agreed that the current behavior is correct and that instead of changing it, it'd be better to keep it as is and instead clarify/improve the docs, so that we can avoid future misunderstandings/confusion like the one that lead to the issue being opened |
|
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. |
currently in the animations package not all newly inserted elements
are treated as entering ones, thus querying them via ':enter' does not
always work as expeted, change such behavior so that all newly inserted
elements are considered entering ones
solves: #30477
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #30477
In the angular package querying "entering" elements not always work, this has caused confusion amongst developers as some of their animations were not being applied as they expected to
(for more details see the issue thread and PR #44216)
What is the new behavior?
All elements added to the DOM are not treated as "moving" ones as such they can be queried with ":enter" as one would expect to
Does this PR introduce a breaking change?
Other information
I think that the changes here are debatable, the behaviour of not treating all new elements as "entering"/"move" ones seems to have been put in place purposely, I believe that the logic being was to only allow ":enter" queries to work on elements that enter by their own accord and not those that enter because of their parents, if an element enters because of its parent then the parent's transition can be ":enter" and the query will be specific for the child itself.
Thus I am not 100% sure if these changes are actually providing a real benefit, or if we should just change the documentation to make clear when child elements can be queried or not based on the existing implementation (meaning, is it really important to be able to do
transition(":enter", [ query(":enter", ...? does that provide a clear better developer experience? are there instances this implementation doesn't provide the functionality needed?)some aio docs animations don't work properly because of this issue (or the lack of clarity around it)