From dc8ecf968c6d38c52b931b719d42791520384136 Mon Sep 17 00:00:00 2001 From: Eirik Backer Date: Mon, 16 Sep 2024 13:57:06 +0200 Subject: [PATCH] fix: syncronized animation bug (#2420) Fixes issue when multiple skeletons or spinners are removed at different times, causing crash ![image](https://github.com/user-attachments/assets/97f2fc9c-5b41-42d7-9b1b-ec1b7468098f) The issue is because `firstOfType` might exist, but it might not have a `currentTime` and setting `myAnimation.currentTime = null` is not allowed. Reported by Team Export Mattilsynet --- .../useSynchronizedAnimation/useSynchronizedAnimation.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react/src/utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.ts b/packages/react/src/utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.ts index 53254affd3..1b6e2e8f0a 100644 --- a/packages/react/src/utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.ts +++ b/packages/react/src/utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.ts @@ -44,12 +44,16 @@ export function useSynchronizedAnimation(animationName: string) { myAnimation.currentTime = 0; } - if (myAnimation && firstOfType && myAnimation !== firstOfType) { + if ( + myAnimation && + firstOfType?.currentTime && + myAnimation !== firstOfType + ) { myAnimation.currentTime = firstOfType.currentTime; } return () => { - if (myAnimation && firstOfType) { + if (myAnimation && firstOfType?.currentTime) { myAnimation.currentTime = firstOfType.currentTime; } };