Skip to content

fix: properly delay intro transitions #12389

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

Merged
merged 4 commits into from
Jul 11, 2024
Merged

fix: properly delay intro transitions #12389

merged 4 commits into from
Jul 11, 2024

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented 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

This works, but the test is failing - I can't figure out how to properly write one. For some reason the opacity that the fade transition calculates is 0, whereas it should be 1 (and in fact is, when testing this in the playground). Update: got it working by applying the style manually, but feels like a hack and it doesn't work for the outro transition, still no idea why this happens

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

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
Copy link

changeset-bot bot commented Jul 10, 2024

🦋 Changeset detected

Latest commit: 9225ed4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@trueadm
Copy link
Contributor

trueadm commented Jul 10, 2024

What about outro transitions? If it starts hidden in the outro, then fades in then out again, does that work correctly with delay?

@dummdidumm
Copy link
Member Author

That's different because the delay says "the animation starts after X miliseconds", and so I would expect the invisible->visible->invisible transition to start only after the given delay. For intro transitions it makes sense to apply the initial value directly because the transitions all start from an invisible state and then go to a visible one.
That said, maybe someone has a bonkers intro transitions where they start in a visible state, meaning the element shows up directly. I'm not sure what the expectation here is then: Should it apply the initial value for the duration of the delay, i.e. be visible, or should it invisible until it starts (because you're starting from "element doesn't exist")? If we say the latter, we could hard-code opacitiy: 0 for the duration of the delay.
I just checked what Svelte 4 does, and applies the same logic as this PR: immediately apply first frame on intro, delay on outro.

@Rich-Harris
Copy link
Member

oops i approved but there's a lint error, looking

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.

Svelte 5: delayed transitions don't apply initial CSS
3 participants