Skip to content
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

Using server side rendering, componentDidMount didn't get called #3

Closed
bryanboyan opened this issue Apr 27, 2015 · 5 comments
Closed

Comments

@bryanboyan
Copy link

Hi, Michael
Did you verify that componentDidMount did get called when hitting localhost:3000/ ?
From react document, https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount, it looks like it's not invoked on server side.

I was thinking about how we can integrate with other Js frameworks if we do server side react.

@mhart
Copy link
Owner

mhart commented Apr 27, 2015

componentDidMount does not get called on the server, that's correct – in the example here, it enables the button on the page once the DOM has been rendered by the browser (not the server).

@mhart
Copy link
Owner

mhart commented Apr 27, 2015

In terms of other JS frameworks, well that's really up to them 😸 – if they allow server-side rendering (ie, rendering in the absence of any DOM, no window, no document, etc, etc) – then it should be possible. If not, then you'll just have to do client-side rendering for that portion and attach them in componentDidMount.

Going to close this – but feel free to keep asking clarifying questions if you want.

@mhart mhart closed this as completed Apr 27, 2015
@bryanboyan
Copy link
Author

Hi, Michael, thanks for answering this, and sorry for replying late.
Then I have a really general question to server-side rendering, since server-side react only renders the relatively static html, and client will render the exact same component to replace them. We do this because of SEO? Imaging the app is really big for server to render, that will cause server load and doesn't help on client load as well?

Thanks

@mhart
Copy link
Owner

mhart commented May 10, 2015

@bryanboyan the advantage of React is that it adds checksums to the nodes when you use renderToString – and then when you render on the client-side, then it checks whether these checksums match what it expects – if they do, then it doesn't need to do anything on the client-side (apart from attach event handlers). So the client-side load is very little. This is explained a little here: https://facebook.github.io/react/docs/top-level-api.html#react.rendertostring

@bryanboyan
Copy link
Author

Michael, that is truly awesome, thanks a lot!

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

No branches or pull requests

2 participants