score:14

Accepted answer

rendertonodestrem() this function returns a readable stream. with this function we still get requests from the browser, we make our initial api requests then we build a tiny snippet of our react application so we attempt to render application. but we just render the bare minimum of it like the first component, the first bit of the html. the instant we get that first little tiny bit of html ready, we send that snippet to the browser. then on the server we put together next tiny little snippet of our html. we then take that tiny snippet and we send it to the browser and then we repeat the same process many times. so with this function we are assembling tiny pieces of our html document and sending them over to the user’s browser.

ttfb: time to first bite this is the number that we really care about when it comes to search engine optimization. it is a duration of how long it took for our server to put together some initial bit of html and send a response back to the browser. it is very widely used by google and other search engines to rate the performance of our page. this is far short in duration with the rendertonodestream() because we are building a tiny bit of html and sending it.

if you start to render your application with nodestream and then you come along a component that needs to redirect, you cannot do redirecting. because once you start piping all that content from the nodestream into the res object, that instantly starts the response and sends it back to the user. imagine users come along with a page that needs to be authorized but it is not, you have to redirect the user with status code change but you cannot change the status code.

if you want to use the rendertonodestream you have to change the entire architecture of the app. instead of next routing, you have to use react-router dom. for react server side, you have to use staticrouter which passes the context prop to all of the components. it is similar to what getinitialprops "context" object. if you are going to use react router dom, then you have to look for all the components and decide what async operations have to be completed before sending the response object. you have to this manually.

technically you cannot use react rendertonodestream with next.js. instead you have to configure webpack, build your own server, most likely express server and implement everything on your own.

next.js is popular because there is alot of work to complete the server-side rendering. however as of now, next.js has no support for rendertonodestream. but it is on the way.


Related Query

More Query from same tag