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

fix(gatsby): Render to pipeable stream in dev SSR #37534

Merged
merged 4 commits into from
Jan 26, 2023

Conversation

panzacoder
Copy link
Contributor

Description

Replaces the react-dom/server api renderToString with renderToPipeableStream in order to support React lazy SSR, the new bundle-splitting solution that shipped with React 18.

Inspired by this comment by @d4v1d82

Documentation

Related Issues

Fixes #36678

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 25, 2023
Copy link
Contributor

@LekoArts LekoArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is identical to

// If no one stepped up, we'll handle it.
if (!bodyHtml) {
try {
const writableStream = new WritableAsPromise()
const { pipe } = renderToPipeableStream(bodyComponent, {
onAllReady() {
pipe(writableStream)
},
onError(error) {
writableStream.destroy(error)
},
})
bodyHtml = await writableStream
} catch (e) {
// ignore @reach/router redirect errors
if (!isRedirect(e)) throw e
}
}
this should be fine 👍

Thanks!

@LekoArts LekoArts added topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 26, 2023
@LekoArts LekoArts merged commit 049e8e1 into gatsbyjs:master Jan 26, 2023
@lezan
Copy link

lezan commented Jan 30, 2023

Hey @LekoArts with gatsby@next (and since this pull) I am not able to use DEV_SSR and Hot Reloading.
I already put an example here.

I am always getting Hydration failed because the initial UI does not match what was rendered on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation)
3 participants