react-resize-panel icon indicating copy to clipboard operation
react-resize-panel copied to clipboard

ReferenceError: document is not defined; SSR.

Open MorpheusFT opened this issue 5 years ago • 2 comments

const doc = document, win = window, div = doc.createElement('div'), { filter, indexOf, map, push, reverse, slice, some, splice } = Array.prototype;

I render it server side first, then later hydrate on the client side, which is probably why your component fails.

MorpheusFT avatar Sep 30 '20 14:09 MorpheusFT

If you are using next js you just have to tell next to import and render the component only on the client and not to apply ssr for that component, this for libraries that for example run only in the browser. I recommend these links

https://nextjs.org/docs/advanced-features/dynamic-import

https://stackoverflow.com/questions/53139884/next-js-disable-server-side-rendering-on-some-pages

willydavid1 avatar Oct 06 '20 00:10 willydavid1

For Next.js, this seems to work for me:

const ResizePanel = dynamic(() => import('react-resize-panel'), { ssr: false });

Would be nice to support SSR I think? Even if it's non-functional and just does the basic DOM element wrapping or whatever.

chriscoyier avatar Feb 22 '21 22:02 chriscoyier