Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lottie SSR issue in BentoGrid #32

Open
KayvanShah1 opened this issue Aug 2, 2024 · 4 comments
Open

Lottie SSR issue in BentoGrid #32

KayvanShah1 opened this issue Aug 2, 2024 · 4 comments

Comments

@KayvanShah1
Copy link

KayvanShah1 commented Aug 2, 2024

Tried dynamic loading with useEffect Hook

⨯ ReferenceError: document is not defined
    at __webpack_require__ (C:\Users\shahk\OneDrive\Projects K1\Personal\portfolio\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\shahk\OneDrive\Projects K1\Personal\portfolio\.next\server\webpack-runtime.js:33:43)
    at eval (./components/ui/bento-grid.tsx:13:70)
    at (ssr)/./components/ui/bento-grid.tsx (C:\Users\shahk\OneDrive\Projects K1\Personal\portfolio\.next\server\app\page.js:206:1)
    at Object.__webpack_require__ [as require] (C:\Users\shahk\OneDrive\Projects K1\Personal\portfolio\.next\server\webpack-runtime.js:33:43)
digest: "1091135423"
 GET / 500 in 697ms
@muhammadashhadgit
Copy link

Same problem

@33929978
Copy link

33929978 commented Aug 8, 2024

Did anyone find a fix? I am experiencing the same issue.

@KayvanShah1
Copy link
Author

Did anyone find a fix? I am experiencing the same issue.

One possible solution is to downgrade the node to 20.x and reinstall node modules

@Sia-WRWD
Copy link

Sia-WRWD commented Aug 13, 2024

The reason this issue is popping up is because of NextJS Server-Side Rendering (SSR) nature, while Lottie utilizes the window object which is not available during SSR, causing the build to fail.

To fix the issue, simply change the code in BentoGrid.tsx for the importing of the lottie library:

import dynamic from 'next/dynamic';

const Lottie = dynamic(() => import('react-lottie'), { ssr: false });

Credits to: Dragos UniqQum

Edit-1: I noticed that using this method will lead to a forEach error, therefore, to resolve that error, try using an alternative library in the name of react-lottie-player which has almost similar options with minor modifications required.

Code with modifications:

import dynamic from 'next/dynamic';

const Lottie = dynamic(() => import('react-lottie-player'), { ssr: false });

<div className={`absolute -bottom-5 right-[5.75rem]`}>
    <Lottie 
        loop={false}
        animationData={animationData}
        play={copied}
        rendererSettings={{
            preserveAspectRatio: 'xMidYMid slice'
        }}
        style={{ height: 300, width: 200 }}
    />
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants