jsonkao / react-scrollama

Simple scrollytelling with the IntersectionObserver in React.
https://jsonkao.github.io/react-scrollama
MIT License
388 stars 30 forks source link

"window" is not available during server side rendering #59

Closed cedricdelpoux closed 3 years ago

cedricdelpoux commented 3 years ago

Hi, the last version 2.2.13 is not compatible with server side rendering

error occurs when calling window.innerHeight.

I need to downgrade to version 2.2.7 to make react-scrollama work with SSR

jsonkao commented 3 years ago

Hey, sorry about that. Do you have suggestions about how to check for SSR/functionally fix this?

Also, would the window event listener calls break?

cedricdelpoux commented 3 years ago

I think it juste a one line check because there is only one window during initialisation.

viewH = typeof window !== undefined ? window.innerHeight : 0;

I made a PR

jsonkao commented 3 years ago

And just to make sure, a default value of 0 wouldn't break any functionality/introduce weird bugs right?

cedricdelpoux commented 3 years ago

It does not change anything for user who don't use SSR