1 | // forward declarations
|
2 | declare global {
|
3 | namespace NodeJS {
|
4 | // eslint-disable-next-line @typescript-eslint/no-empty-interface
|
5 | interface ReadableStream {}
|
6 |
|
7 | // eslint-disable-next-line @typescript-eslint/no-empty-interface
|
8 | interface WritableStream {}
|
9 | }
|
10 |
|
11 | /**
|
12 | * Stub for https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
13 | */
|
14 | // eslint-disable-next-line @typescript-eslint/no-empty-interface
|
15 | interface AbortSignal {}
|
16 |
|
17 | /**
|
18 | * Stub for https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
19 | */
|
20 | // eslint-disable-next-line @typescript-eslint/no-empty-interface
|
21 | interface ReadableStream {}
|
22 | }
|
23 |
|
24 | import { ReactElement, ReactNode } from "react";
|
25 | import { ErrorInfo } from "./client";
|
26 |
|
27 | export interface RenderToPipeableStreamOptions {
|
28 | identifierPrefix?: string;
|
29 | namespaceURI?: string;
|
30 | nonce?: string;
|
31 | bootstrapScriptContent?: string;
|
32 | bootstrapScripts?: string[];
|
33 | bootstrapModules?: string[];
|
34 | progressiveChunkSize?: number;
|
35 | onShellReady?: () => void;
|
36 | onShellError?: (error: unknown) => void;
|
37 | onAllReady?: () => void;
|
38 | onError?: (error: unknown, errorInfo: ErrorInfo) => string | void;
|
39 | }
|
40 |
|
41 | export interface PipeableStream {
|
42 | abort: (reason?: unknown) => void;
|
43 | pipe: <Writable extends NodeJS.WritableStream>(destination: Writable) => Writable;
|
44 | }
|
45 |
|
46 | /**
|
47 | * Only available in the environments with [Node.js Streams](https://nodejs.dev/learn/nodejs-streams).
|
48 | *
|
49 | * @see [API](https://reactjs.org/docs/react-dom-server.html#rendertopipeablestream)
|
50 | *
|
51 | * @param children
|
52 | * @param options
|
53 | */
|
54 | export function renderToPipeableStream(children: ReactNode, options?: RenderToPipeableStreamOptions): PipeableStream;
|
55 |
|
56 | /**
|
57 | * Render a React element to its initial HTML. This should only be used on the server.
|
58 | * React will return an HTML string. You can use this method to generate HTML on the server
|
59 | * and send the markup down on the initial request for faster page loads and to allow search
|
60 | * engines to crawl your pages for SEO purposes.
|
61 | *
|
62 | * If you call `ReactDOMClient.hydrateRoot()` on a node that already has this server-rendered markup,
|
63 | * React will preserve it and only attach event handlers, allowing you
|
64 | * to have a very performant first-load experience.
|
65 | */
|
66 | export function renderToString(element: ReactElement): string;
|
67 |
|
68 | /**
|
69 | * Render a React element to its initial HTML. Returns a Readable stream that outputs
|
70 | * an HTML string. The HTML output by this stream is exactly equal to what
|
71 | * `ReactDOMServer.renderToString()` would return.
|
72 | *
|
73 | * @deprecated
|
74 | */
|
75 | export function renderToNodeStream(element: ReactElement): NodeJS.ReadableStream;
|
76 |
|
77 | /**
|
78 | * Similar to `renderToString`, except this doesn't create extra DOM attributes
|
79 | * such as `data-reactid`, that React uses internally. This is useful if you want
|
80 | * to use React as a simple static page generator, as stripping away the extra
|
81 | * attributes can save lots of bytes.
|
82 | */
|
83 | export function renderToStaticMarkup(element: ReactElement): string;
|
84 |
|
85 | /**
|
86 | * Similar to `renderToNodeStream`, except this doesn't create extra DOM attributes
|
87 | * such as `data-reactid`, that React uses internally. The HTML output by this stream
|
88 | * is exactly equal to what `ReactDOMServer.renderToStaticMarkup()` would return.
|
89 | */
|
90 | export function renderToStaticNodeStream(element: ReactElement): NodeJS.ReadableStream;
|
91 |
|
92 | export interface RenderToReadableStreamOptions {
|
93 | identifierPrefix?: string;
|
94 | namespaceURI?: string;
|
95 | nonce?: string;
|
96 | bootstrapScriptContent?: string;
|
97 | bootstrapScripts?: string[];
|
98 | bootstrapModules?: string[];
|
99 | progressiveChunkSize?: number;
|
100 | signal?: AbortSignal;
|
101 | onError?: (error: unknown, errorInfo: ErrorInfo) => string | void;
|
102 | }
|
103 |
|
104 | export interface ReactDOMServerReadableStream extends ReadableStream {
|
105 | allReady: Promise<void>;
|
106 | }
|
107 |
|
108 | /**
|
109 | * Only available in the environments with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) (this includes browsers, Deno, and some modern edge runtimes).
|
110 | *
|
111 | * @see [API](https://reactjs.org/docs/react-dom-server.html#rendertoreadablestream)
|
112 | */
|
113 | export function renderToReadableStream(
|
114 | children: ReactNode,
|
115 | options?: RenderToReadableStreamOptions,
|
116 | ): Promise<ReactDOMServerReadableStream>;
|
117 |
|
118 | export const version: string;
|
119 |
|
120 | export as namespace ReactDOMServer;
|