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

Async React.renderToString for server-side rendering #3793

Closed
xpepermint opened this issue Apr 30, 2015 · 6 comments
Closed

Async React.renderToString for server-side rendering #3793

xpepermint opened this issue Apr 30, 2015 · 6 comments

Comments

@xpepermint
Copy link

It would really help if we could use the async version of the React.renderToString when rendering on the server-side.

app.get('*', function (req, res) {

  Router.run(routes, req.path, (Handler, router) => {
    // var content = React.renderToString(<Handler/>);
    // res.render('index', { content: content });
    React.renderToString(<Handler/>, function(content) {
      res.render('index', { content: content });
    });
});
@sophiebits
Copy link
Contributor

This is something we want to do, but it requires more thought around how components are rendered because the currently solution always renders something synchronously. In your example, what does it wait for before returning the result? Anyway, we're tracking this in #1739.

@xpepermint
Copy link
Author

Great. As you can see I'm rendering the component server-side with nodejs/express and using a sync method does not feel right (blocking). Thanks.

@sophiebits
Copy link
Contributor

React.renderToString doesn't do any I/O so you wouldn't gain anything from it being async in its current form.

@zpao
Copy link
Member

zpao commented Apr 30, 2015

Where you might benefit is not so much async but streaming markup generation. Follow along in #3009 for more there.

@xpepermint
Copy link
Author

Thanks! Following #3009 then.

@gaearon
Copy link
Collaborator

gaearon commented Mar 24, 2021

There’s new work in this area in #20970.

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

4 participants