Skip to content

🎥 Make videos programmatically with React

Fix lottie freeze on last frame when not looping

copilot-swe-agent[bot]75f144f2fefe
diff --git a/packages/lottie/src/test/utils.test.ts b/packages/lottie/src/test/utils.test.ts
index d2741a988b..e0a33f3204 100644
--- a/packages/lottie/src/test/utils.test.ts
+++ b/packages/lottie/src/test/utils.test.ts
@@ -8,7 +8,14 @@ describe('getNextFrame', () => {
});
it('returns the last frame if current frame is bigger than total frames', () => {
- expect(getLottieFrame({currentFrame: 23, totalFrames: 20})).toBe(20);
+ expect(getLottieFrame({currentFrame: 23, totalFrames: 20})).toBe(19);
+ });
+
+ it('freezes on last valid frame to prevent animation disappearing', () => {
+ // This test specifically validates the fix for the issue where
+ // non-looping animations disappear after playing once
+ expect(getLottieFrame({currentFrame: 100, totalFrames: 30})).toBe(29);
+ expect(getLottieFrame({currentFrame: 1000, totalFrames: 60})).toBe(59);
});
});
@@ -44,7 +51,7 @@ describe('getNextFrame', () => {
totalFrames: 20,
direction: 'backward',
}),
- ).toBe(0);
+ ).toBe(1);
});
});
diff --git a/packages/lottie/src/utils.ts b/packages/lottie/src/utils.ts
index 1202b52e12..fd408c111c 100644
--- a/packages/lottie/src/utils.ts
+++ b/packages/lottie/src/utils.ts
@@ -13,7 +13,7 @@ export const getLottieFrame = ({
}: Params) => {
const nextFrame = loop
? currentFrame % totalFrames
- : Math.min(currentFrame, totalFrames);
+ : Math.min(currentFrame, totalFrames - 1);
if (direction === 'backward') {
return totalFrames - nextFrame;