Prevent View Transition fallback from waiting on looping animations (#8331)
* Prevent View Transition fallback from waiting on looping animations * Filter out infinite animations
This commit is contained in:
parent
af41b03d05
commit
7a894eec3e
2 changed files with 19 additions and 1 deletions
5
.changeset/late-foxes-juggle.md
Normal file
5
.changeset/late-foxes-juggle.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Prevent View Transition fallback from waiting on looping animations
|
|
@ -98,6 +98,17 @@ const { fallback = 'animate' } = Astro.props as Props;
|
|||
return wait;
|
||||
}
|
||||
|
||||
function isInfinite(animation: Animation) {
|
||||
const effect = animation.effect;
|
||||
if(
|
||||
!effect ||
|
||||
!(effect instanceof KeyframeEffect) ||
|
||||
!effect.target
|
||||
) return false;
|
||||
const style = window.getComputedStyle(effect.target, effect.pseudoElement);
|
||||
return style.animationIterationCount === "infinite";
|
||||
}
|
||||
|
||||
const parser = new DOMParser();
|
||||
|
||||
async function updateDOM(html: string, state?: State, fallback?: Fallback) {
|
||||
|
@ -221,8 +232,10 @@ const { fallback = 'animate' } = Astro.props as Props;
|
|||
|
||||
if (fallback === 'animate') {
|
||||
// Trigger the animations
|
||||
const currentAnimations = document.getAnimations();
|
||||
document.documentElement.dataset.astroTransitionFallback = 'old';
|
||||
const finished = Promise.all(document.getAnimations().map(a => a.finished));
|
||||
const newAnimations = document.getAnimations().filter(a => !currentAnimations.includes(a) && !isInfinite(a));
|
||||
const finished = Promise.all(newAnimations.map(a => a.finished));
|
||||
const fallbackSwap = () => {
|
||||
swap();
|
||||
document.documentElement.dataset.astroTransitionFallback = 'new';
|
||||
|
|
Loading…
Reference in a new issue