(node: React.ReactNode, options?: Options)
| 6 | import { stripImagePreloadLinks } from '../shared/utils/strip-image-preload-links'; |
| 7 | |
| 8 | export const render = async (node: React.ReactNode, options?: Options) => { |
| 9 | const reactDOMServer = await import('react-dom/server').then((m) => { |
| 10 | if ('default' in m) { |
| 11 | return m.default; |
| 12 | } |
| 13 | return m; |
| 14 | }); |
| 15 | |
| 16 | const html = await new Promise<string>((resolve, reject) => { |
| 17 | const ErrorBoundary = createErrorBoundary(reject); |
| 18 | reactDOMServer |
| 19 | .renderToReadableStream( |
| 20 | <Suspense> |
| 21 | <ErrorBoundary>{node}</ErrorBoundary> |
| 22 | </Suspense>, |
| 23 | { |
| 24 | onError(error: unknown) { |
| 25 | reject(error); |
| 26 | }, |
| 27 | progressiveChunkSize: Number.POSITIVE_INFINITY, |
| 28 | }, |
| 29 | ) |
| 30 | .then(async (stream) => { |
| 31 | await stream.allReady; |
| 32 | return readStream(stream); |
| 33 | }) |
| 34 | .then((result) => resolve(stripImagePreloadLinks(result))) |
| 35 | .catch(reject); |
| 36 | }); |
| 37 | |
| 38 | if (options?.plainText) { |
| 39 | return toPlainText(html, options.htmlToTextOptions); |
| 40 | } |
| 41 | |
| 42 | const doctype = |
| 43 | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; |
| 44 | |
| 45 | const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, '')}`; |
| 46 | |
| 47 | if (options?.pretty) { |
| 48 | return pretty(document); |
| 49 | } |
| 50 | |
| 51 | return document; |
| 52 | }; |
no test coverage detected
searching dependent graphs…