bs-breakpoints icon indicating copy to clipboard operation
bs-breakpoints copied to clipboard

window is undefined and result is NULL in combination with Next.JS

Open sixtyniner-official opened this issue 5 years ago • 3 comments

I've tried to use a package in Next.JS project with server-side rendering SSR.

On first reload window is not defined error is thrown.

When a component is rendered, state value for a breakpoint is null

component

sixtyniner-official avatar Jun 04 '19 07:06 sixtyniner-official

Hi @mestro67,

First of all thanks for using my plugin 👍

It seems it's a specificty of Next.js, but you'll find some workarounds here: https://github.com/zeit/next.js/wiki/FAQ

My libs need to access the window object because it adds a polyfill for IE users if needed. I do that because I follow Bootstrap 4 browser support

Johann-S avatar Jun 04 '19 08:06 Johann-S

did you find a solution @mestro67 ?

Johann-S avatar Jun 06 '19 07:06 Johann-S

Hi! Getting same issue. I think, that the root cause is that library code is evaluated on the stage of defining import and not after calling init(). I did a workaround by importing library via dynamic import inside useEffect by it looks ugly and it requires to do the same trick every time you use it inside a new file/component and work with lib as a Promise like thing. Can we lazy-evaluate stuff that needs window upon init call?

iaroslavshvets avatar Feb 01 '21 15:02 iaroslavshvets