Skip to content

ExecJS environment defines window #614

@NGMarmaduke

Description

@NGMarmaduke
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions