router5 / react-router5

Helpers for using router5 with React [MOVED]
MIT License
83 stars 8 forks source link

server rendering error #11

Closed olessavluk closed 8 years ago

olessavluk commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

:tada: 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.

olessavluk commented 8 years ago

You are talking about this ?) - https://github.com/olessavluk/react-router5/commit/12aad1612002f7d5380c60370e9dbeaffa55376e

troch commented 8 years ago

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 commented 8 years ago

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

troch commented 8 years ago

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

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