[Question] - Is it faster than renderToStaticMarkup?
jackyef opened this issue · 5 comments
Hi, really interesting project!
I am currently writing a library for data fetching. Since the library uses hooks, I am not sure if I can use the visitor
function to collect the promises during SSR. Currently what I am doing is calling renderToStaticMarkup
repeatedly.
I am thinking to at least change renderToStaticMarkup
to prepass
repeatedly, if it actually helps with performance. My question is, is prepassing
repeatedly faster than renderToStaticMarkup
repeatedly? I did some testing but couldn't reach a conclusion.
Thanks!
Hiya 🙌
Yes, generally it’s built to be a little faster and more mindful of the event loop. This is important so that repeated renders don’t contest the single thread of your server.
To your other question, it’d be recommended to implement your promises using suspense. So during server-side rendering mode you’d attempt to throw them during render.
Thanks for the reply!
Great to know that prepass
should be faster.
To your other question, it’d be recommended to implement your promises using suspense. So during server-side rendering mode you’d attempt to throw them during render.
Assuming I am using react-ssr-prepass
and throw the promises on SSR mode, how would I catch them, resolve, and resume rendering? I see that the visitor function is passed (element, instance)
params, but neither seems to be able to help catch promises. Since I am using functional components with hooks, I don't think I could assign a method to the instance
. Am I missing something here?
@jackeyf if you use the suspense-like method you don’t need to catch anything.
Any suspense like render (a promise thrown during render) will be picked up by prepass automatically. That means instead of awaiting and repeatedly calling renderToStaticMarkup
manually you’d just wait for the promise that prepass returns to resolve.
Oh, really really sorry. I totally missed that in the readme! That's really neat!
I will definitely try that then. Thanks a lot @kitten !
No worries! I’ll go ahead and close this then for now 🙌 but feel free to send more questions