Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfranco committed Jan 15, 2025
1 parent 12da9b7 commit a044e83
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions packages/calcite-components/src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,6 @@ export async function whenTransitionDone(
type TransitionOrAnimation = "transition" | "animation";
type TransitionOrAnimationInstance = CSSTransition | Animation;

const activeAnimationsFinishPromises = new WeakMap<Animation, Promise<void>>();

async function triggerFallbackStartEnd(start: () => void, end: () => void): Promise<void> {
// offset callbacks by a frame to simulate event counterparts
await nextFrame();
Expand All @@ -629,11 +627,6 @@ async function triggerFallbackStartEnd(start: () => void, end: () => void): Prom
end?.();
}

function triggerEndActionAndClearAnim(animation: Animation, end: () => void): void {
activeAnimationsFinishPromises.delete(animation);
end?.();
}

function findAnimation(
targetEl: HTMLElement,
type: TransitionOrAnimation,
Expand Down Expand Up @@ -673,20 +666,15 @@ export async function whenTransitionOrAnimationDone(
return triggerFallbackStartEnd(onStart, onEnd);
}

if (activeAnimationsFinishPromises.has(anim)) {
return activeAnimationsFinishPromises.get(anim);
}

onStart?.();
activeAnimationsFinishPromises.set(
anim,
anim.finished
.then(() => {})
.catch(() => {
// swallow error if canceled
})
.finally(() => triggerEndActionAndClearAnim(anim, onEnd)),
);

try {
await anim.finished;
} catch {
// swallow error if canceled
} finally {
onEnd?.();
}
}

function nextFrame(): Promise<void> {
Expand Down

0 comments on commit a044e83

Please sign in to comment.