Skip to content

Commit

Permalink
chore(repo): fixes WebStream import issue in renderAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Sep 20, 2023
1 parent ac9b107 commit 2eeebfc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/render/src/render-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { type ReadableStream } from 'node:stream/web';
import { convert } from 'html-to-text';
import pretty from 'pretty';
import { type ReactNode } from 'react';
import { renderToReadableStream, renderToStaticMarkup } from 'react-dom/server';
import react from 'react-dom/server';

const { renderToStaticMarkup } = react;
const renderToStream =
// Note: only available in platforms that support WebStreams
// https://react.dev/reference/react-dom/server/renderToString#alternatives
react.renderToReadableStream ||
// Note: only available in Node
react.renderToPipeableStream;

export const renderToString = async (children: ReactNode) => {
const stream = await renderToReadableStream(children);
const stream = await renderToStream(children);

const html = await readableStreamToString(
// ReactDOMServerReadableStream behaves like ReadableStream
Expand Down

0 comments on commit 2eeebfc

Please sign in to comment.