react-async-ssr
react-async-ssr copied to clipboard
`renderToString` and `renderToStaticMarkup` sync methods
Re-export ReactDOMServer's renderToString and renderToStaticMarkup methods in this module so it becomes a drop-in replacement for ReactDOMServer.
const ReactDOMServer = require('react-async-ssr');
// Original sync methods
ReactDOMServer.renderToString( e );
ReactDOMServer.renderToStaticMarkup( e );
// Async methods
await ReactDOMServer.renderToStringAsync( e );
await ReactDOMServer.renderToStaticMarkupAsync( e );
Or create alternative sync methods which do the same as ReactDOMServer's methods, but handle Suspense (but suspend all Suspense elements, since it can't wait for promises to resolve).
This is a good idea. In my app I have two react roots, one for the head (which I render to static markup) and one for the body, which would use react-async-ssr.
I ended up needing to do this:
import ReactDOMServer from 'react-dom/server'
import ReactDOMServerAsync from 'react-async-ssr'
Hi. I'm sorry to say that, having thought about it, I don't want to re-export .renderToString and .renderToStaticMarkup from ReactDOM.
I think it's better to reserve these method names for possible future sync implementations which could partially-support Suspense by immediately rendering the fallback.
It'd be nice to be able to import all the methods from one package, but I don't think it's such hardship to do import from 'react-dom/server'.
Sorry to disappoint you.