react-async-ssr icon indicating copy to clipboard operation
react-async-ssr copied to clipboard

`renderToString` and `renderToStaticMarkup` sync methods

Open overlookmotel opened this issue 6 years ago • 2 comments

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).

overlookmotel avatar Jun 07 '19 14:06 overlookmotel

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'

heygrady avatar Sep 10 '19 16:09 heygrady

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.

overlookmotel avatar Sep 14 '19 12:09 overlookmotel