question: why don't use renderToNodeStream instead of renderToString?
See original GitHub issueHi guys, I love this boilerplace, very clean. But I have a question about react-dom/server
Why donāt we use renderToNodeStream instead of renderToString?
Rendering to a stream can reduce the time to first byte (TTFB) for your content, sending the beginning of the document down the wire to the browser before the next part of the document has even been generated. All major browsers will start parsing and rendering the document earlier when the content is streamed from the server this way.
import { renderToNodeStream } from "react-dom/server"
import MyPage from "./MyPage"app.get("/", (req, res) => {
res.write("<!DOCTYPE html><html><head><title>My Page</title></head><body>");
res.write("<div id='content'>");
const stream = renderToNodeStream(<MyPage/>);
stream.pipe(res, { end: false });
stream.on('end', () => {
res.write("</div></body></html>");
res.end();
});
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Is it ok to use ReactDOMServer.renderToString in the ...
I have used it and now my event handlers are not called. By rendering the component in js object rather than dom. are...
Read more >Upgrading to React 18 on the server Ā· Discussion #22
However, it's not deprecated, so you can keep using renderToString . In React 18, we're adding very limited <Suspense> support to renderToStringĀ ...
Read more >ReactDOMServer
The following methods can be used in the environments that don't support streams: ... Instead, use renderToNodeStream on the server and ReactDOM.
Read more >ReactDOMServer | Working and Examples of Dom Server ...
This method is just like renderToString, the only difference is that the additional DOM attributes are not created which is used internally by...
Read more >Streaming Server-Side Rendering and Caching at Spectrum
Using renderToNodeStream. The API for streaming server-side rendering isn't all that different from the standard renderToString API.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iāve made a fork to test this here: https://github.com/Rid/react-cool-starter
However there are a few issues:
Youāre welcome to fork my fork and see if you can address these issues some other way.
@Rid Iāll check your fork, then see that I can fix or not. Anyway, thanks for your support. @wellyshen your project structure & coding standard looks great, I love it š