Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

check if "document" is present (server-side rendering) #111

Open
indeyets opened this issue Nov 12, 2018 · 2 comments
Open

check if "document" is present (server-side rendering) #111

indeyets opened this issue Nov 12, 2018 · 2 comments

Comments

@indeyets
Copy link

componentDidUpdate() calls dispatchEvent which unconditionally calls document.createEvent('Event');

The problem is that document global is not available when server-side rendering is used (either in isomorphic scenarios or in tests).

Simple if (typeof document !== 'undefined') guard should be enough to fix this

@FrancescoCioria
Copy link
Contributor

Hi @indeyets
As far as I know renderToString (from react-dom/server) calls only componentWillMount, while componentDidMount/Update are called in the client during the hydrate.

Why is componentDidUpdate being called on your server? are you sure?

@indeyets
Copy link
Author

Update happens during tests. I noticed issue while checking logs of our test runs actually.

Re-rendering on server-side is not a recommended practice, but not exactly prohibited.

I can find more details later today if you think that is important

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

No branches or pull requests

2 participants