Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some guards to keep execution in a node context from throwing ReferenceErrors #123

Closed
wants to merge 3 commits into from

Conversation

swansong
Copy link

My team is using react-filepond in a React UI kit, and we love it! There's one issue we ran into with server-side-rendered applications that imported our implementing component: we'd get ReferenceErrors for performance, window and document. These guards here make it so our component renders fine on the server and works in the browser.

@swansong
Copy link
Author

sorry something is up with this, gonna close until I have it sorted

@swansong swansong closed this Sep 19, 2018
@swansong swansong reopened this Sep 19, 2018
@rikschennink
Copy link
Collaborator

@swansong Thanks for reporting! If I understand correctly the navigator object is available on your node instance? Maybe it's defined by another module?

I found this Stack Overflow answer that can help detect a browser environment, I like the solutation so will probably go with that:
https://stackoverflow.com/a/31090240/1774081

As the source is not in the repository yet I'll make the changes to the source files and publish a new version later this week or at the start of the next.

@rikschennink
Copy link
Collaborator

@swansong I've updated the code with this check

const isBrowser = new Function('try {return this===window}catch(e){return false}');

Will publish a new version later today. Unfortunately, the source files are not in the repo just jet so I'll have to close the pull request.

@rikschennink
Copy link
Collaborator

Just published version 2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants