Skip to content

fixes async setState calls with ssr#54

Merged
jamiebuilds merged 1 commit intojamiebuilds:masterfrom
anilanar:fix-ssr
Sep 19, 2017
Merged

fixes async setState calls with ssr#54
jamiebuilds merged 1 commit intojamiebuilds:masterfrom
anilanar:fix-ssr

Conversation

@anilanar
Copy link
Contributor

  • Correctly checks whether component has already loaded or not in componentWillMount.

With SSR, componentWillMount was registering some setTimeout callbacks, calling setState asynchronously etc. This PR fixes it.

As far as I can see, res.resolved is never assigned to any value so it's always falsy. When componentWillMount is trigged; if loading is false, there's no point in doing the rest of the stuff. Because either loaded or error must be defined, so one of them can be rendered.

BTW, I have a suggestion for another PR: loading is a computable value: loading === !loaded && !error. So it makes sense to turn it into a computed value to reduce possible mistakes later on.

- Correctly checks whether component has already loaded or not in
componentWillMount.
@carinakoo
Copy link

Would be great to see this merged to eliminate this warning on server rendering. 🙏

Warning: setState(...): Can only update a mounting component. This usually means you called setState() outside componentWillMount() on the server. This is a no-op. Please check the code for the LoadableComponent component.

@kettanaito
Copy link

Are you planning to merge this change?

It eliminates the error mentioned above gracefully.

@jamiebuilds jamiebuilds merged commit 1846782 into jamiebuilds:master Sep 19, 2017
@iamstarkov
Copy link

@tajo @thejameskyle can you release a new version with this patch?

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.

5 participants