Skip to content

Commit

Permalink
empty
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 7, 2024
1 parent 0c3546c commit 30fcaa9
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions packages/docusaurus/src/client/renderToHtml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,11 @@
*/

import type {ReactNode} from 'react';
// @ts-expect-error: see https://github.com/facebook/react/issues/31134
import {renderToReadableStream as renderToReadableStreamImpl} from 'react-dom/server.browser';
import {
renderToString,
type renderToReadableStream as renderToReadableStreamType,
} from 'react-dom/server';
import {renderToReadableStream} from 'react-dom/server.browser';
import {text} from 'stream/consumers';

const renderToReadableStream: typeof renderToReadableStreamType =
renderToReadableStreamImpl;

export async function renderToHtml(app: ReactNode): Promise<string> {
return new Promise((resolve, reject) => {
renderToReadableStream(app, {
onError: (error) => reject(error),
}).then(async (stream) => {
await stream.allReady;
// @ts-expect-error: it works fine
const html = await text(stream);

// TODO remove this test
if (html !== renderToString(app)) {
throw new Error('Bad');
}

resolve(html);
}, reject);
});
const stream = await renderToReadableStream(app);
await stream.allReady;
return text(stream);
}

0 comments on commit 30fcaa9

Please sign in to comment.