projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.58k stars 1.17k forks source link

Fix SSR (#75, #315) #782

Closed danlobo closed 2 years ago

danlobo commented 3 years ago

Replace broken package 'closest' with polyfill Fix webpack4 'window not an object' (https://stackoverflow.com/questions/55849240/window-is-not-defined-after-a-build-with-webpack)

Checklist

What?

'window is not an object' errors when using server-side.

Why?

Webpack 4 has issues with window object when the context doesn't have it. It works on browser, but not on server-side.

There are workarounds to not change the settings, but involves dynamic imports inside client-side methods (componentDidUpdate / useEffect ).

Custom classes in separated files, like nodes, factories and widgets doesn't work because imports aren't possible.

The package closest relies on Element object, which doesn't exist on server-side context.

How?

This fixes webpack4 issue as seen here.

The closestpackage was removed and replaced with a polyfill.

Feel good image:

LOL

picodoth commented 3 years ago

When will this be merged?

dylanvorster commented 2 years ago

I think this was already fixed