-
Notifications
You must be signed in to change notification settings - Fork 752
Description
- My app crashes with
react-rails
, so I've included the stack trace and the exact steps which make it crash.
The ExecJSRenderer
defines window as the global scope for server rendering here: ExecJSRenderer:36
This can cause major issues when using 3rd party libraries that perform type of checks on the window variable to detect the presence of a browser environment.
I have created an example Rails app to reproduce the issue:
https://github.com/NGMarmaduke/react-rails-window-example
The sample code with the window check is from yahoo's subscribe-ui-event
The resulting error is:
ExecJS::ProgramError
ReferenceError: document is not defined
Realistically window shouldn't be defined or available on the server, initial investigation of why this is being defined points me at react-builds/react-server.js, it is assigning variables on the window:
window.React = React;
window.ReactDOM = ReactDOM;
window.ReactDOMServer = ReactDOMServer;
As an aside ReactDOM
isn't required for server rendering.