Skip to content
This repository was archived by the owner on May 23, 2018. It is now read-only.

server rendering error #11

Closed
olessavluk opened this issue Nov 23, 2015 · 7 comments
Closed

server rendering error #11

olessavluk opened this issue Nov 23, 2015 · 7 comments
Labels

Comments

@olessavluk
Copy link

I am getting error when trying to render on the server:

Warning: React can't find the root component node for data-reactid value .ba9ic960ao.1.2. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.

TypeError: Cannot read property 'firstChild' of undefined
at Object.ReactMount.findComponentRoot
...(and so on)

(Here I created repo to reproduce this issue: https://github.com/olessavluk/r5bug )
I'm using node v5.0.0 & npm v3.4.1. And I have only one veriosn of React installed, because find ./ -name 'react' returns only one result .//node_modules/react.

So I think problem in this file https://github.com/router5/react-router5/blob/master/modules/routeNode.js#L21. Because you are adding listener in constructor and removing it in componentWillUnmout, but unmount never gets executed on the server.

@troch
Copy link
Member

troch commented Nov 23, 2015

I am quite inexperienced with universal applications so thank you for raising potential issues.
I cloned and ran your example, the error goes away by removing the input element in Timer component. Not sure what that means.

@olessavluk
Copy link
Author

I have created new branch (logall) and put logs everywhere to see what is actually going on.
Log output

As you can see, listener executes setState after rendering is complete and this actually causes an error.

@troch
Copy link
Member

troch commented Nov 26, 2015

🎉 I think I managed to fix it. The problem is not with componentWillUnmount but with suff in component constructor (componentWillMount) which should be in componentDidMount.

I will commit a fix and release it later tonight.

troch added a commit that referenced this issue Nov 26, 2015
@olessavluk
Copy link
Author

@troch
Copy link
Member

troch commented Nov 26, 2015

Yes, exactly. I also moved the check for the listeners plugin to component did mount so you are not forced to use it on the server side.

1.0.1 has been published

@troch
Copy link
Member

troch commented Nov 26, 2015

Thank you very much for raising that bug and taking the time to create a repo. I really appreciate. 👍

@troch
Copy link
Member

troch commented Nov 26, 2015

Linking it to other similar issues, in case that helps others.

RickWong/react-isomorphic-starterkit#77
denvned/isomorphic-relay-router#5

@troch troch closed this as completed Nov 26, 2015
@troch troch added the bug label Nov 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants