-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Should renderToString call life cycle methods? #2674
Comments
It's true the "lifecycle" is not really a cycle on the server. For your case with listeners and whatnot, it's probably better to set those up in |
Cool, thanks for the reasoning behind it. I'll keep my ear to the ground should anything change with componentWillMount |
Came across this whilst investigating another unrelated issue (page requesting route twice). When we call renderToString on the server, React will try and call:
Calling mountComponent in turn triggers the life cycle method componentWillMount, which seems odd to me as it essentially isn't being mounted, it's only utilizing this method (as far as I can see) to generate the markup thus has a broken life cycle.
Not having a symmetrical life cycle can lead to odd issues with lingering objects e.g. when component listens for events outside it's own life cycle in componentWillMount and does not get a proper componentWillUnmount call, it does not get a chance to clean up it's references.
The main question is should the renderToString method invoke life cycle methods at all, as they'll never have a complete cycle? I understand we could just move bindings to componentDidMount but it still seems wrong to me to have an asymmetric life cycle. Perhaps we could block the call to componentWillMount by including
so it doesn't run when called server side?
Just some thoughts anyway :) really enjoying React!
The text was updated successfully, but these errors were encountered: