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