-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[18] renderToPipeableStream doc #4485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ The following methods can be used in both the server and browser environments: | |
|
|
||
| These additional methods depend on a package (`stream`) that is **only available on the server**, and won't work in the browser. | ||
|
|
||
| - [`renderToNodeStream()`](#rendertonodestream) | ||
| - [`renderToPipeableStream()`](#rendertopipeablestream) | ||
| - [`renderToReadableStream()`](#rendertoreadablestream) | ||
| - [`renderToNodeStream()`](#rendertonodestream) (Deprecated) | ||
| - [`renderToStaticNodeStream()`](#rendertostaticnodestream) | ||
|
|
||
| * * * | ||
|
|
@@ -54,8 +56,41 @@ Similar to [`renderToString`](#rendertostring), except this doesn't create extra | |
| If you plan to use React on the client to make the markup interactive, do not use this method. Instead, use [`renderToString`](#rendertostring) on the server and [`ReactDOM.hydrateRoot()`](/docs/react-dom-client.html#hydrateroot) on the client. | ||
|
|
||
| * * * | ||
| ### `renderToPipeableStream()` {#rendertopipeablestream} | ||
|
|
||
| ### `renderToNodeStream()` {#rendertonodestream} | ||
| ```javascript | ||
| ReactDOMServer.renderToPipeableStream(element, options) | ||
| ``` | ||
|
|
||
| Render a React element to its initial HTML. Returns a [Control object](https://github.com/facebook/react/blob/3f8990898309c61c817fbf663f5221d9a00d0eaa/packages/react-dom/src/server/ReactDOMFizzServerNode.js#L49-L54) that allows you to pipe the output or abort the request. Fully supports Suspense and streaming of HTML with "delayed" content blocks "popping in" later through javascript execution. [Read more](https://github.com/reactwg/react-18/discussions/37) | ||
|
|
||
| If you call [`ReactDOM.hydrateRoot()`](/docs/react-dom-client.html#hydrateroot) on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience. | ||
|
|
||
| > Note: | ||
| > | ||
| > Server-only. This API is not available in the browser. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth highlighting that this is a Node.js specific API and that "modern server environments should use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait.. do we not consider Node.js modern anymore? 😄 I'd understand "edge server environments" but "modern" sounds harsh. |
||
| > | ||
|
|
||
| * * * | ||
|
|
||
| ### `renderToReadableStream()` {#rendertoreadablestream} | ||
|
|
||
| ```javascript | ||
| ReactDOMServer.renderToReadableStream(element, options); | ||
| ``` | ||
|
|
||
| Render a React element to its initial HTML. Returns a [Readable Stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream). Fully supports Suspense but not streaming of HTML. [Read more](https://github.com/reactwg/react-18/discussions/127) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the API that canonical for streaming HTML. The one that doesn't stream HTML is |
||
|
|
||
| If you call [`ReactDOM.hydrateRoot()`](/docs/react-dom-client.html#hydrateroot) on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience. | ||
|
|
||
| > Note: | ||
| > | ||
| > Server-only. This API is not available in the browser. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually not server-only. https://github.com/facebook/react/blob/main/packages/react-dom/server.browser.js#L40 It's more intended for Service Workers specifically though. |
||
| > | ||
|
|
||
| * * * | ||
|
|
||
| ### `renderToNodeStream()` {#rendertonodestream} (Deprecated) | ||
|
|
||
| ```javascript | ||
| ReactDOMServer.renderToNodeStream(element) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename that
Controltype. I think of it as aPipeableStreamobject. It's kind of like Node's "ReadableStream" except limited to the pipe function and with the addition of theabort().