Server side rendering `window` behaves differently than Node.js?
damassi opened this issue · 4 comments
Hi! Excellent library and very well written codebase (ty!)
I have a quick question around server side rendering react components and code execution.
We've been SSR rendering our primary web app (using styled-components) with Node.js with no trouble and I am certain that SSR is well supported at the library level. However, attempting to render the same code using this library in Rails yields problems around window. My operating assumption is that said code could seamlessly transfer to a react on rails environment, but perhaps i'm missing a detail somewhere. I'm wondering if this might be related to how ExecJS might be evaluating the code? Does this ring any bells?
The window object is part of the browser's JavaScript environment and is not available on the server.
Hi @ahangarha - I understand that. The problem is that the package styled-components -- which is SSR friendly -- references window in the code for browser side behavior, and is guarded for a server-side context as mentioned in the issue above. However, in a react-on-rails environment, whether this is guarded or not seems to not matter. As the code is evaluated by ExecJS during the pre-render phase, the window keyword seems to be leading to an error.
@Judahmeek Any insight?
I'm so sorry! This was meant for the react_on_rails repo. Just now realizing.