wnr / element-resize-detector

Optimized cross-browser resize listener for elements.
MIT License
1.32k stars 118 forks source link

Latest release breaks SSR #91

Closed danielstaleiny closed 6 years ago

danielstaleiny commented 6 years ago

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

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

wnr commented 6 years ago

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.

danielstaleiny commented 6 years ago

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 6 years ago

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.

danielstaleiny commented 6 years ago

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