wnr/element-resize-detector

Latest release breaks SSR

danielstaleiny opened this issue · 4 comments

There is upstream issue with window is undefined crashing SSR react apps. Packages affected react-sizeme and everything build upon this.

ctrlplusb/react-sizeme#134
https://github.com/tsuyoshiwada/react-stack-grid/issues/47

wnr commented

Hi and thanks for the report. This library needs a window context in order to do its job, and should therefore only be created when there is a window object available. What is the expected fix from this library?

As a side note, how can the window object be undefined? That seems very strange to me.

Pleasure,
I understand the intention and I agree that this library should be used only within browser but we have serverside rendering. There is use case where react-sizeme is used on first render within serverside context. I don't expect react-sizeme or this library to calculate properties of the browser but it shouldn't crash either. The only job of this library in this context is not to crash and return undefined/null value, once browser takes over, do it's job.

I am already disabling this library on serverside but because those upstream libraries provide HOC I am just wrapping my components and waiting for browser to take over.

wnr commented

I see, thanks for the explanation. Yes, I agree that this would be a desired behaviour of React-resizeme and similar high-level APIs. However, the sole purpose of this library is to observe resize events of elements in a browser context - so I think that this library should not be invoked at all in other circumstances. I'm closing this issue, and hope that you will be able to find a solution upstream. Feel free to ping me in comments in the upstream issues if needed.

I understand and I agree. I will seek solution upstream, thank you for listening.