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

Animate breaks when used along with fly transition #6001

Closed
shreyas44 opened this issue Feb 18, 2021 · 10 comments
Closed

Animate breaks when used along with fly transition #6001

shreyas44 opened this issue Feb 18, 2021 · 10 comments
Labels

Comments

@shreyas44
Copy link

shreyas44 commented Feb 18, 2021

Describe the bug
The flip animation and fly transition break when used together, not sure which one is causing the other to break however.

Logs
Console is clear

To Reproduce

REPL: https://svelte.dev/repl/46298c2514ef4215b06ddab7c7bc44e0?version=3.32.3

In the REPL, repeatedly click on next (fast) and this happens
Screen Shot 2021-02-18 at 10 50 27 PM

Expected behavior
With regards to the above screenshot, it's supposed to look something like this
Screen Shot 2021-02-18 at 10 50 33 PM

Information about your Svelte project:

  • Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10): Chrome 88.0.4324.96

  • Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc): MacOS 11.2.1

  • Svelte version (Please check you can reproduce the issue with the latest release!): 3.32.3

  • Whether your project uses Webpack or Rollup: Rollup

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?

Annoying and breaks the page

Additional context
If required, I could share a more real world reproduction

@apriliandi246
Copy link

I think a simple solution to solve this problem just change the duration of transition and animate. I tried duration to 600ms or less than 600ms and it's work...

@shreyas44
Copy link
Author

shreyas44 commented Feb 18, 2021

Yup, that works in this case.

However, if you go to https://shreyas44.vercel.app and scroll down to the My Projects section and keep clicking the next button, the same thing happens. And in that case the duration is set to 400ms.

@kindoflew
Copy link
Contributor

I think fly has to have a significantly shorter duration than flip. When they are the same duration, there is a race condition somewhere and the animation isn't calling the function to remove the position: absolute that it uses to figure out where things are. If you inspect one of the stuck items and look in the actual console, you'll see it's temporary absolute position is never removed.

@shreyas44
Copy link
Author

@kindoflew that does make sense.

One thing I forgot to mention is that, this problem doesn't occur when the transition is only set to in, similar to #3202. However, I'm guessing this is because the animate doesn't affect the element until it finishes it's in transition?

I tried a workaround where I use a shouldTransition state variable, and if it's set to true, render the element with the animate directive else without it. When the next/back button is clicked, this would first set shouldTransition to false resulting in rendering the element without the animate directive (only if it's in the edge card that will be removed from the DOM) and then set the shouldTransition to true, which results in only the fly transition and not flip animate acting on the card leaving the DOM. First problem with this is that it's very hacky. Second, the svelte compiler raises an error An element that uses the animate directive must be the immediate child of a keyed each block, because I use an if block inside the each block and I'm guessing this error is raised because it could cause errors at runtime?

@kindoflew
Copy link
Contributor

kindoflew commented Feb 19, 2021

Probably also related to #4732. The docs on animate do say that about being the immediate child, I'm assuming so Svelte can know specifically which items to move to new positions before animating. The solution for your portfolio might be to forgo using flip and instead use a carousel component like svelte-carousel or roll your own.

@twobitfool
Copy link

Seems to happen when using flip with any transition: scale, fade, fly, etc.

Demo (REPL)

flipflop

Similar to #4910, and probably related to #4732

@pushkine
Copy link
Contributor

Duplicate #4910

@pejalo
Copy link

pejalo commented Jan 19, 2023

I wonder if this is related to my StackOverflow post: how to animate:flip with in/out:fade?

REPL

Screen Recording 2023-01-17 at 9 53 39 PM

@Blankeos
Copy link

Blankeos commented Apr 29, 2024

Still having problems with this :(.

Repro: https://svelte.dev/repl/4d641551906e4b82a893918bb43fd6d3?version=4.2.12

Svelte Animate and Transition bug

Edit: Just fixed it thanks to a solution here: #4910 (comment)

@dummdidumm
Copy link
Member

Fixed in Svelte 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants