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

revert handling of JavaScript animations during view transitions #10841

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

martrapp
Copy link
Member

Changes

This is edge-case-land of Astro's view transition simulation when you do not use CSS only but also want to combine it with JavaScript animations.

While #10787 worked fine for Firefox on desktops, it introduced a regression on mobile WebKit browsers.

Video.mp4

The blinking screen in the middle of the animation is a result of un-animated rendering before the animation kicks in. Reverting #10787 fixes this.

As an afterthought, it would have been better to switch micro tasks instead of yielding to the tasks queue. But after consulting the spec again (https://drafts.csswg.org/css-view-transitions-1/), I'm not sure whether this goes into the right direction. In browsers with native view transition support
viewTransition.finished would not wait for arbitrary animations triggered by viewTransition.ready.

It would only include animations that depend on the view transition pseudo elements. Translated to Astro that would mean only animations that depend on data-astro-transition* attributes. This thinking leads to a straight forward solution for JavaScript animations:
If you want to delay finished in Astro's view transition simulation for a JavaScript animation triggered by ready, add a noop animation that is triggered by data-astro-transition-fallback="new". This will automatically be covered by fallback="animate".

<style is:global>
    /* Example: For Astro's view transition simulation, 
       ensure that `viewTransition.finished` happens 
       at least 1.5s after `viewTransition.ready` */ 
    @keyframes noop {}
    :root[data-astro-transition-fallback="new"] {animation: noop 0s 1.5s}
</style>

Testing

No automated tests as this only shows on browsers which we do not include in our e2e tests.

After removing the round trip through the task queue, the transition looks smooth again. The noop CSS animation shown above was used to fix the original issue faced in #10787

Video2.mp4

Docs

n.a. / Bug fix

Copy link

changeset-bot bot commented Apr 22, 2024

🦋 Changeset detected

Latest commit: 37c458d

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

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 22, 2024
@martrapp martrapp merged commit a2df344 into main Apr 22, 2024
13 checks passed
@martrapp martrapp deleted the mt/revert branch April 22, 2024 10:18
@astrobot-houston astrobot-houston mentioned this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants