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

Animation with delay can lead to outdated css rules #2871

Closed
Harald-1 opened this issue May 26, 2019 · 6 comments
Closed

Animation with delay can lead to outdated css rules #2871

Harald-1 opened this issue May 26, 2019 · 6 comments

Comments

@Harald-1
Copy link
Contributor

I played around with the todo list from the animation tutorial (https://svelte.dev/tutorial/animate) and adapted it like so:

Then I continued playing around and replaced the delay with an unreasonable huge number (3s). The behaviour seems very odd when you interact with the todo list before the animation actually starts, leaving the todo items on akward positions somewhere in between, where they should not be: https://svelte.dev/repl/31c4535d1e2c4a548ec55f6fc739facc?version=3.4.2
To reproduce, check and remove todos before the 3s delay.

After debugging the code I found out what the problem is:

  1. When a delay is specified for a CSS animation, the css rule is created and applied with node.style.cssText.
    if (css) node.style.cssText += css(0, 1);
  2. Normally, when the animation would start after the delay a "named" rule would be created...
    name = create_rule(node, 0, 1, duration, 0, easing, css);

    ...which could be deleted later.
    if (css) delete_rule(node, name);
  3. Since the user interacts with the items before the delay expires the rule created at 1) stays at the element and deleting it fails, because of the missing name.

I also found out, that there is a TODO here, which points out the solution:

if (delay) node.style.cssText = css_text; // TODO create delayed animation instead?

I adapted animation.js accordingly - using animation-delay instead and will create a pull request to solve this issue shortly.
Still the items are on akward positions, but only until the delay expires. Then the items are repositioned automatically.

Note, that according to MDN, this will work only for IE10 or later: https://developer.mozilla.org/en-US/docs/Web/CSS/animation-delay

Thank you for the great work, Svelte is a cool thing! 👍😀

Harald-1 added a commit to Harald-1/svelte that referenced this issue May 26, 2019
@Rich-Harris
Copy link
Member

Released 3.4.4 with the partial fix, but will leave this open until we've squashed the starting position bug

@Harald-1
Copy link
Contributor Author

Thank you for merging! I will have a look on it.

Harald-1 added a commit to Harald-1/svelte that referenced this issue May 30, 2019
@Harald-1
Copy link
Contributor Author

It took me a while to find a possible solution. The problem with the wrong starting position was a result of transition + animation. Please review pull-request #2904. Thank you!

Harald-1 added a commit to Harald-1/svelte that referenced this issue May 30, 2019
Harald-1 added a commit to Harald-1/svelte that referenced this issue May 30, 2019
Harald-1 added a commit to Harald-1/svelte that referenced this issue May 30, 2019
@Harald-1
Copy link
Contributor Author

Cleaned up the commit history, sorry for the clutter. 😁

Rich-Harris added a commit that referenced this issue Jun 6, 2019
@Conduitry Conduitry added the bug label Sep 12, 2019
@stale
Copy link

stale bot commented Jun 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 27, 2021
@stale
Copy link

stale bot commented Jul 11, 2021

This issue has been closed as it was previously marked as stale and saw no subsequent activity.

@stale stale bot closed this as completed Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants