unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/embed
MIT License
4.51k stars 728 forks source link

Fix for server-side-rendering (NextJS). Window is now only accessed in a useEffect #366

Closed OMMatte closed 10 months ago

OMMatte commented 10 months ago

The problem: When using NextJS and server-side-rendering (SSR) the program crashes because the window object is beeing accessed outside of useEffects.

Possible solutions/hacks: Using dynamic imports. However this causes new problems becuase you need to have a ref to the editor. It is far from straight-forward how to get around this and I tried but it causes other problems such as callbacks not beeing called etc. You can try following this guide to fix it: https://github.com/vercel/next.js/issues/4957

Actual solution: Make sure you only access the window/document object inside a useEffect