Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderToString and renderToStaticMarkup sync methods #19

Open
overlookmotel opened this issue Jun 7, 2019 · 2 comments
Open

renderToString and renderToStaticMarkup sync methods #19

overlookmotel opened this issue Jun 7, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@overlookmotel
Copy link
Owner

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

@heygrady
Copy link

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 added a commit to heygrady/react-async-ssr that referenced this issue Sep 10, 2019
@overlookmotel
Copy link
Owner Author

overlookmotel commented Sep 14, 2019

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 overlookmotel changed the title Add ReactDOMServer's renderToString and renderToStaticMarkup to exports? renderToString and renderToStaticMarkup sync methods Sep 14, 2019
@overlookmotel overlookmotel added the enhancement New feature or request label Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants