Skip to content

Commit ca2cbf5

Browse files
authored
fix: lottie layout shift while lazy loading (#4588)
1 parent e8a2675 commit ca2cbf5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/shared/src/components/LottieAnimation.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
1+
import React, { lazy, Suspense } from 'react';
22
import { useQuery } from '@tanstack/react-query';
33
import type { LottieComponentProps } from 'lottie-react';
44
import type { ReactElement } from 'react';
5-
import dynamic from 'next/dynamic';
65
import { RequestKey } from '../lib/query';
76
import { disabledRefetch } from '../lib/func';
87
import { fromCDN } from '../lib';
@@ -11,9 +10,9 @@ export type LottieAnimationProps = {
1110
className?: string;
1211
src: string;
1312
basePath?: string;
14-
} & Omit<LottieComponentProps, 'animationData' | 'width' | 'height'>;
13+
} & Omit<LottieComponentProps, 'animationData' | 'width' | 'height' | 'ref'>;
1514

16-
const Lottie = dynamic(
15+
const Lottie = lazy(
1716
() => import(/* webpackChunkName: "lottieReact" */ 'lottie-react'),
1817
);
1918

@@ -51,12 +50,14 @@ export const LottieAnimation = ({
5150
});
5251

5352
return (
54-
<Lottie
55-
{...lottieProps}
56-
className={className}
57-
loop={loop}
58-
autoplay={autoplay}
59-
animationData={animationData}
60-
/>
53+
<Suspense fallback={<div className={className} />}>
54+
<Lottie
55+
{...lottieProps}
56+
className={className}
57+
loop={loop}
58+
autoplay={autoplay}
59+
animationData={animationData}
60+
/>
61+
</Suspense>
6162
);
6263
};

0 commit comments

Comments
 (0)