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

Svelte 5: delayed transitions don't apply initial CSS #10876

Closed
Rich-Harris opened this issue Mar 22, 2024 · 3 comments · Fixed by #12389
Closed

Svelte 5: delayed transitions don't apply initial CSS #10876

Rich-Harris opened this issue Mar 22, 2024 · 3 comments · Fixed by #12389
Assignees
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the bug

If a transition has a delay, it should begin in its 0 state, not its 1 state

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE02PwW4DIQxEf8Ulh7RSJXLphbIr5TuaHDaLiayygMAbKUL8e2HTKr15rHljTxGWHGahvorw04JCiWOM4l3wPXaRb-gYm85hTXPf6Dwnijye_IlpiSExFLCTQahgU1hg_2Akp8lnYgp-_9nNDhlulOniEIZGuIxtr-Uzz-vLyhw8BK9mR_P3UF7fYBj_YS-_Yx05XK8OtXwgG152ZP-8tZ_UEZ5fqP7kUIpBN90VfBwOtY6bQLMV0DK2mCLJVmiNl2DIEhqhOK1Yz_UHA4G56ywBAAA=

Logs

No response

System Info

next

Severity

annoyance

@PatrickG
Copy link

PatrickG commented Mar 25, 2024

fill: 'backwards' should fix that.
It seems like currently fill: 'forwards' is used. That might be problematic anyway. E.g. when you want to change the opacity with an inline style on an element that also uses in:fade transition.
Idealy, the animation should be removed after it finished.
Fixed in #11216 by removing the animation after it finished.

@unleashy
Copy link

unleashy commented May 7, 2024

Is there any workaround for this issue? Quite the annoying one

@mquandalle
Copy link

mquandalle commented May 21, 2024

A workaround would be to remove the delay and instead provide a custom easing function with an extended duration :

<script>
  import { fade } from "svelte/transition";
  import { linear } from "svelte/easing";

  function workaroundSvelte5BugWithDelay({ delay, duration, easing = linear }) {
    let virtual_duration = delay + duration;
    let threshold = delay / virtual_duration;
    return {
      duration: virtual_duration,
      easing: (x) => x < threshold ? 0 : easing((x - threshold) / (1 - threshold)),
    };
  }
</script>

<div in:fade={workaroundSvelte5BugWithDelay({ delay: 500, duration: 300 })}>hello</div>

Svelte 5 REPL

@dummdidumm dummdidumm self-assigned this Jul 10, 2024
dummdidumm added a commit that referenced this issue Jul 10, 2024
WAAPI applies the styles of a delayed animation only when that animation starts. In the case of fade-in transitions that means the element is visible, then goes invisible and fades in. Fix that by never applying a delay on intro transitions, instead add keyframes of the initial state for the duration of the delay.

Fixes #10876
Rich-Harris added a commit that referenced this issue Jul 11, 2024
* fix: properly delay intro transitions

WAAPI applies the styles of a delayed animation only when that animation starts. In the case of fade-in transitions that means the element is visible, then goes invisible and fades in. Fix that by never applying a delay on intro transitions, instead add keyframes of the initial state for the duration of the delay.

Fixes #10876

* fix bug, make test pass

* make test more selfcontained, test outro delay aswell and add functionality for that in animation-helpers

* lint

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants