Skip to content

Conversation

@yezhizhen
Copy link
Member

@yezhizhen yezhizhen commented Mar 14, 2025

This improves the behavior of transition toggling, cancellation, and
delay. In particular, there are many improvements with how transitions
are started when replacing an existing one.

Servo PR: servo/servo#35978

Co-authored-by: Martin Robinson [email protected]
Signed-off-by: Euclid Ye [email protected]
Signed-off-by: Martin Robinson [email protected]

Copy link
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

This needs to be rebased on top of the latest main

@yezhizhen yezhizhen force-pushed the fix-transition-order branch from 230370b to ed063e7 Compare March 14, 2025 07:55
@yezhizhen yezhizhen changed the title Fix transition order Fix broken transition toggle Mar 14, 2025
@yezhizhen yezhizhen marked this pull request as ready for review March 14, 2025 11:11
@yezhizhen yezhizhen requested a review from nicoburns March 14, 2025 11:11
@yezhizhen yezhizhen changed the title Fix broken transition toggle Fix broken transition toggle and cancelling Mar 14, 2025
@yezhizhen yezhizhen force-pushed the fix-transition-order branch 2 times, most recently from 7f43b7b to 090b1fe Compare March 14, 2025 16:37
@yezhizhen
Copy link
Member Author

yezhizhen commented Mar 14, 2025

@nicoburns nicoburns dismissed their stale review March 14, 2025 23:29

PR has now been rebased

@yezhizhen yezhizhen changed the title Fix broken transition toggle and cancelling Fix broken transition toggle, cancellation, and delay Mar 15, 2025
@yezhizhen yezhizhen force-pushed the fix-transition-order branch 2 times, most recently from 80fa179 to 560638c Compare March 16, 2025 07:28
@yezhizhen
Copy link
Member Author

What should I rebase on now? I got many conflicts when rebasing on main.

@Loirooriol
Copy link
Collaborator

I force-pushed the main branch to sync changes from upstream, which is not ideal for PRs.

With your branch at 08279e1, you should be able to do

git rebase --onto main 7ee9643e7ff1633c709f4ffd683050eb3c726ec9 fix-transition-order

Where 7ee9643 is the nearest common ancestor of your branch and https://github.com/servo/stylo/commits/2025-03-11/

@yezhizhen yezhizhen force-pushed the fix-transition-order branch 2 times, most recently from 172dac0 to 28fc84e Compare March 17, 2025 10:35
@yezhizhen
Copy link
Member Author

yezhizhen commented Mar 17, 2025

Somehow I cannot compile anymore.. I just fetched the latest Servo main branch.

I am on the latest Servo main branch.
Latest Stylo branch, with my five commits.
But I get a lot of

error[E0053]: method `report_error` has an incompatible type for trait
   --> components\script\dom\fontface.rs:180:20
    |
180 |         _location: cssparser::SourceLocation,
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `style::values::SourceLocation`, found `cssparser::SourceLocation`

@nicoburns
Copy link
Collaborator

Somehow I cannot compile anymore.. I just fetched the latest Servo main branch.
I am on the latest Servo main branch. Latest Stylo branch, with my five commits.

@yezhizhen You upgraded to the latest Stylo branch a little too quickly! CI is still running on the corresponding Servo PR (servo/servo#35990). Your code should compile again once that merges. Until then you can run against the 2025-03-12 Stylo branch.

@yezhizhen
Copy link
Member Author

Haha thanks Nico! I will get back tomorrow then :)

@yezhizhen yezhizhen force-pushed the fix-transition-order branch 2 times, most recently from 4a2dd8c to 4ef8b50 Compare March 17, 2025 14:55
@yezhizhen
Copy link
Member Author

yezhizhen commented Mar 17, 2025

I still cannot compile locally, with latest pulled repo
I think there is something wrong with current Cargo.toml in Servo for using local stylo.

I made some adjustments to Cargo.toml in Servo. It starts to compile, but has following errors now:

error[E0277]: the trait bound `ElementState: MallocSizeOf` is not satisfied
   --> D:\Rust\Cargo\git\checkouts\stylo-482338307e42a9ea\6aa5733\style\servo\selector_parser.rs:778:26
    |
778 | #[derive(Debug, Default, MallocSizeOf)]
    |                          ^^^^^^^^^^^^ the trait `MallocSizeOf` is not implemented for `ElementState`

EDIT: Seems to work now after servo/servo#36011

@yezhizhen yezhizhen requested a review from Loirooriol March 18, 2025 02:57
@yezhizhen
Copy link
Member Author

it will be easier to see what you have fixed. Thank you!

current.servo+stylo.main.branch.mp4
after.apply.fix.mp4

@mrobinson
Copy link
Member

@yezhizhen Thanks! I'll take a look at this today.

@mrobinson
Copy link
Member

mrobinson commented Mar 28, 2025

Okay. I've spent some time looking more closely at this change and I think it's a good start! Apologies for the current mess, but I think this is a good opportunity to actually implement the specification in the order it is written.

  1. Add a start_new_transition method that can be used for early returns.
  2. Restructure start_transition_if_applicable to match the specification.
    • First check all the conditions of step 1, caching any values that are used twice, such as:
          let combined_duration_is_greater_than_zero = ...
    • If all the conditions for 1 are met, you can do an early return:
          if ... &&
             combined_duration &&
             existing_transition.is_none()
        {
           self.start_new_transition(...);
           return;
        }
    • After step 1 you can do an early return if there is no pre-existing transition as all the subsequent steps rely on there being one:
           if let Some(existing_transition) = existing_transition else {
               return;
           }
  3. The final part of start_transition_if_applicable would be checking the various specification conditions related to existing_transition in the order specified, finally canceling existing_transition and starting the new transition in step 4 if necessary.

@yezhizhen
Copy link
Member Author

Okay. I've spent some time looking more closely at this change and I think it's a good start! Apologies for the current mess, but I think this is a good opportunity to actually implement the specification in the order it is written.

Thanks for the suggestions! When I opened this PR I try to work around original code without altering it too much. It is nice we can do this now :)

@yezhizhen
Copy link
Member Author

yezhizhen commented Mar 29, 2025

@mrobinson I just restructured the code completely to follow exact same order as spec is written in. And my newly added wpt-tests and other manual tests are still passing.

EDIT: Latest test result: https://github.com/yezhizhen/servo/actions/runs/14153448812

@yezhizhen yezhizhen force-pushed the fix-transition-order branch 2 times, most recently from ecdab05 to e46917b Compare March 30, 2025 06:26
@mrobinson
Copy link
Member

@yezhizhen I've pushed a couple commits onto your branch with some minor changes. Please take a look. Do these seeem okay to you?

Copy link
Member Author

@yezhizhen yezhizhen left a comment

Choose a reason for hiding this comment

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

@mrobinson LGTM mostly, but Condition 3 of step 1 is not checked in your latest commit.
I also have some other questions below :)

Comment on lines +1229 to +1247
match ignore_transitions {
IgnoreTransitions::Canceled => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I feel a bit clumsy, as this check is done in each iteration despite the static execution path. And we need to introduce a extra enum.

Does compiler optimize it away? Would it still be better, if we just create two functions?

Copy link
Member

Choose a reason for hiding this comment

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

I think that two functions would lead to a good deal of code repetition, so a single function makes more sense to me. This kind of check should be very cheap. Another option here could be using bitflags.

&self,
context: &mut StyleContext<Self>,
old_styles: &ElementStyles,
old_styles: &mut ElementStyles,
Copy link
Member Author

Choose a reason for hiding this comment

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

It is not mutated tho. Would it be better to just remove mut?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that's correct, but these changes are unrelated so should be posted in another PR.

Comment on lines 1061 to 1067
if !has_running_transition && (transitionable && from != to) && (duration + delay > 0.0) {
// > 3. the element does not have a completed transition for the property or the end value
// > of the completed transition is different from the after-change style for the property
let mut start_new_transition = !has_completed_transition;
if has_completed_transition {
let completed_transition = old_transition.as_ref().unwrap();
start_new_transition = completed_transition.property_animation.to != to;
Copy link
Member Author

@yezhizhen yezhizhen Apr 2, 2025

Choose a reason for hiding this comment

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

This condition 3 also needs to be checked in step 1.
Right now it is removed in your latest commit.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch. I've added this back.

@yezhizhen
Copy link
Member Author

https://github.com/yezhizhen/servo/actions/runs/14217536133

@mrobinson The latest try run in Servo PR for this Stylo PR is successful.
Also, what do you think about above unresolved conversation?

&self,
context: &mut StyleContext<Self>,
old_styles: &ElementStyles,
old_styles: &mut ElementStyles,
Copy link
Member

Choose a reason for hiding this comment

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

Yep, that's correct, but these changes are unrelated so should be posted in another PR.

Comment on lines +1229 to +1247
match ignore_transitions {
IgnoreTransitions::Canceled => {
Copy link
Member

Choose a reason for hiding this comment

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

I think that two functions would lead to a good deal of code repetition, so a single function makes more sense to me. This kind of check should be very cheap. Another option here could be using bitflags.

Comment on lines 1061 to 1067
if !has_running_transition && (transitionable && from != to) && (duration + delay > 0.0) {
// > 3. the element does not have a completed transition for the property or the end value
// > of the completed transition is different from the after-change style for the property
let mut start_new_transition = !has_completed_transition;
if has_completed_transition {
let completed_transition = old_transition.as_ref().unwrap();
start_new_transition = completed_transition.property_animation.to != to;
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch. I've added this back.

@mrobinson
Copy link
Member

@yezhizhen Sorry, for some reason my comment on the unresolved conversation was left in a draft state. You can find it above now.

@mrobinson
Copy link
Member

If this looks okay to you, I will squash the changes and land the PR.

@yezhizhen
Copy link
Member Author

yezhizhen commented Apr 2, 2025

@mrobinson LGTM. Please land :)

For the Servo PR, I believe that I need to rebase and revert Cargo.toml and Cargo.lock?

@mrobinson mrobinson force-pushed the fix-transition-order branch from 33247f9 to f51e372 Compare April 2, 2025 17:41
…re like the specification

This improves the behavior of transition toggling, cancellation, and
delay. In particular, there are many improvements with how transitions
are started when replacing an existing one.

Co-authored-by: Martin Robinson <[email protected]>
Signed-off-by: Euclid Ye <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
@mrobinson mrobinson force-pushed the fix-transition-order branch from f51e372 to ea495b1 Compare April 2, 2025 17:43
@mrobinson mrobinson changed the title Fix broken transition toggle, cancellation, and delay Rework ElementAnimationSet::start_transition_if_applicable to be more like the specification Apr 2, 2025
Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

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

Apologies for the long process to review this!

@mrobinson
Copy link
Member

I'm going to land this one event though the Servo PR isn't approved yet as it shouldn't cause any issues in Servo except another test will start passing.

@mrobinson mrobinson added this pull request to the merge queue Apr 4, 2025
Merged via the queue into servo:main with commit 127952e Apr 4, 2025
3 checks passed
@yezhizhen yezhizhen deleted the fix-transition-order branch April 4, 2025 08:15
@yezhizhen
Copy link
Member Author

I'm going to land this one event though the Servo PR isn't approved yet as it shouldn't cause any issues in Servo except another test will start passing.

Should be fine as Cargo.lock in Servo main branch hasn't updated yet.

github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Apr 7, 2025
More details in Stylo PR: servo/stylo#145

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes 
- fixes #35833
- fixes #35982

<!-- Either: -->
- [x] There are new passing test: `css/css-logical/animation-004.html:
Transitions from physical to logical update when the direction is
changed`

Created new test files as well: 

1. `css-transitions/transition-remove-and-change-immediate.html`
2.  `css-transitions/transition-zero-duration-with-delay.html`
3. `css-transitions/transitioncancel-003.html`

<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->

<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->

cc @Asun0204  @xiaochengh @stevennovaryo

Signed-off-by: Euclid Ye <[email protected]>
TG199 pushed a commit to TG199/servo that referenced this pull request Apr 10, 2025
More details in Stylo PR: servo/stylo#145

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes 
- fixes servo#35833
- fixes servo#35982

<!-- Either: -->
- [x] There are new passing test: `css/css-logical/animation-004.html:
Transitions from physical to logical update when the direction is
changed`

Created new test files as well: 

1. `css-transitions/transition-remove-and-change-immediate.html`
2.  `css-transitions/transition-zero-duration-with-delay.html`
3. `css-transitions/transitioncancel-003.html`

<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->

<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->

cc @Asun0204  @xiaochengh @stevennovaryo

Signed-off-by: Euclid Ye <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants