gergely-nagy / react-pricing-table

:euro: Fast, flexible, simple pricing tables in React.
MIT License
25 stars 13 forks source link

React Server Side Routing window not defined #4

Closed xavisavvy closed 5 years ago

xavisavvy commented 5 years ago

Is there any way to easily accommodate for React-router server side rendering w/ Webpack (example setup https://alligator.io/react/react-router-ssr/)? Trying to squeeze some SEO, and despite my best efforts with some pretty gnarly hacks I still get window is not defined

Error:

... /node_modules/react-pricing-table/lib/react-pricing-table.min.js:6
ReferenceError: window is not defined

Some other peeps who seemed to have same issue on other react components but fixed it - https://github.com/airbnb/lottie-web/issues/440

heshamelmasry77 commented 5 years ago

i have the same problem :(

heshamelmasry77 commented 5 years ago

i found a fix :

if(typeof window !== "undefined"){
    window.scrollTo (0, 0);
  }

i don't understand it but it works

HeadsongStudio commented 5 years ago

I get the same issue using Nextjs. There are several spots in react-pricing-table/lib/react-pricing-table.js that access the window object without null checking first.

heshamelmasry77 commented 5 years ago

@HeadsongStudio try to use my solution it works well on my side

gergely-nagy commented 5 years ago

I'm trying to fix this week but I appreciate any help I can get as I recently started a new project and don't have much time any more.

omjokine commented 5 years ago

I had this same problem and turns out that main reason for this is "style-loader" library that is in use. I replaced that with "iso-morphic-style-loader" and that fixes the problem.

https://github.com/gergely-nagy/react-pricing-table/pull/6

Coriou commented 5 years ago

This was effectively fixed by @omjokine and published to NPM in 0.0.3, think we can close this issue. Thanks for the work !