Skip to content
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

Rename renderToStream to renderToNodeStream. #10425

Merged
merged 2 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/docs/reference-react-dom-node-stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ Unlike other packages in React, `ReactDOMNodeStream` depends on a package (`stre

The `ReactDOMNodeStream` object allows you to render your components in Node.js and stream the resulting markup.

- [`renderToStream()`](#rendertostream)
- [`renderToStaticStream()`](#rendertostaticstream)
- [`renderToNodeStream()`](#rendertonodestream)
- [`renderToStaticNodeStream()`](#rendertostaticnodestream)

* * *

## Reference

### `renderToStream()`
### `renderToNodeStream()`

```javascript
ReactDOMNodeStream.renderToStream(element)
ReactDOMNodeStream.renderToNodeStream(element)
```

Render a React element to its initial HTML. This should only be used in Node.js; it will not work in the browser, since the browser does not support Node.js streams. React will return a [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) that outputs an HTML string. The HTML output by this stream will be exactly equal to what [`ReactDOMServer.renderToString`](https://facebook.github.io/react/docs/react-dom-server.html#rendertostring) would return. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.
Expand All @@ -35,12 +35,12 @@ Note that the stream returned from this method will return a byte stream encoded

* * *

### `renderToStaticStream()`
### `renderToStaticNodeStream()`

```javascript
ReactDOMNodeStream.renderToStaticStream(element)
ReactDOMNodeStream.renderToStaticNodeStream(element)
```

Similar to [`renderToStream`](#rendertostream), except this doesn't create extra DOM attributes such as `data-reactid`, that React uses internally. This is useful if you want to use React as a simple static page generator, as stripping away the extra attributes can save lots of bytes.
Similar to [`renderToNodeStream`](#rendertonodestream), except this doesn't create extra DOM attributes such as `data-reactid`, that React uses internally. This is useful if you want to use React as a simple static page generator, as stripping away the extra attributes can save lots of bytes.

Note that the stream returned from this method will return a byte stream encoded in utf-8. If you need a stream in another encoding, take a look a project like [iconv-lite](https://www.npmjs.com/package/iconv-lite), which provides transform streams for transcoding text.
8 changes: 4 additions & 4 deletions scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@
"202": "ReactDOM.render(): Invalid component element. Instead of passing a class like Foo, pass React.createElement(Foo) or <Foo />.",
"203": "ReactDOM.render(): Invalid component element. This may be caused by unintentionally loading two independent copies of React.",
"204": "ReactDOM.render(): Invalid component element.",
"205": "renderToStream(): Invalid component element.",
"206": "renderToStaticStream(): Invalid component element.",
"207": "ReactDOMServer.renderToStream(): The streaming API is not available in the browser. Use ReactDOMServer.renderToString() instead.",
"208": "ReactDOMServer.renderToStaticStream(): The streaming API is not available in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.",
"205": "renderToNodeStream(): Invalid component element.",
"206": "renderToStaticNodeStream(): Invalid component element.",
"207": "ReactDOMServer.renderToNodeStream(): The streaming API is not available in the browser. Use ReactDOMServer.renderToString() instead.",
"208": "ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.",
"209": "renderToString(): Invalid component element.",
"210": "renderToStaticMarkup(): Invalid component element.",
"211": "Missing injection for fiber findDOMNode",
Expand Down
3 changes: 1 addition & 2 deletions scripts/fiber/tests-passing-except-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
* gives source code refs for unknown prop warning for exact elements in composition (ssr)

207 changes: 139 additions & 68 deletions scripts/fiber/tests-passing.txt

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"bundleSizes": {
"react.development.js (UMD_DEV)": {
"size": 65980,
"gzip": 16788
"size": 65895,
"gzip": 16725
},
"react.production.min.js (UMD_PROD)": {
"size": 6734,
Expand All @@ -25,40 +25,40 @@
"gzip": 6703
},
"react-dom.development.js (UMD_DEV)": {
"size": 634292,
"gzip": 144575
"size": 635059,
"gzip": 144541
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 119041,
"gzip": 37995
},
"react-dom.development.js (NODE_DEV)": {
"size": 593703,
"gzip": 134999
"size": 593871,
"gzip": 135054
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 116323,
"gzip": 37033
},
"ReactDOMFiber-dev.js (FB_DEV)": {
"size": 590523,
"gzip": 134461
"size": 590691,
"gzip": 134515
},
"ReactDOMFiber-prod.js (FB_PROD)": {
"size": 423907,
"gzip": 94912
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 53332,
"gzip": 13396
"size": 53359,
"gzip": 13402
},
"ReactTestUtils-dev.js (FB_DEV)": {
"size": 53124,
"gzip": 13357
"size": 53151,
"gzip": 13364
},
"react-dom-unstable-native-dependencies.development.js (UMD_DEV)": {
"size": 88275,
"gzip": 22341
"size": 88186,
"gzip": 22325
},
"react-dom-unstable-native-dependencies.production.min.js (UMD_PROD)": {
"size": 17748,
Expand All @@ -81,56 +81,56 @@
"gzip": 15736
},
"react-dom-server.browser.development.js (UMD_DEV)": {
"size": 122873,
"gzip": 31036
"size": 124076,
"gzip": 31288
},
"react-dom-server.browser.production.min.js (UMD_PROD)": {
"size": 21199,
"gzip": 8114
"size": 21207,
"gzip": 8118
},
"react-dom-server.browser.development.js (NODE_DEV)": {
"size": 92049,
"gzip": 23628
"size": 92358,
"gzip": 23695
},
"react-dom-server.browser.production.min.js (NODE_PROD)": {
"size": 19962,
"gzip": 7604
"size": 19970,
"gzip": 7609
},
"ReactDOMServer-dev.js (FB_DEV)": {
"size": 91242,
"gzip": 23555
"size": 91551,
"gzip": 23617
},
"ReactDOMServer-prod.js (FB_PROD)": {
"size": 49636,
"gzip": 13862
"size": 49652,
"gzip": 13866
},
"react-dom-server.node.development.js (NODE_DEV)": {
"size": 94782,
"gzip": 24195
"size": 95135,
"gzip": 24258
},
"react-dom-server.node.production.min.js (NODE_PROD)": {
"size": 21053,
"gzip": 7964
"size": 21077,
"gzip": 7968
},
"react-art.development.js (UMD_DEV)": {
"size": 373518,
"gzip": 82706
"size": 307667,
"gzip": 66584
},
"react-art.production.min.js (UMD_PROD)": {
"size": 93115,
"gzip": 28802
"size": 56773,
"gzip": 17592
},
"react-art.development.js (NODE_DEV)": {
"size": 294907,
"gzip": 62698
"size": 294998,
"gzip": 62730
},
"react-art.production.min.js (NODE_PROD)": {
"size": 55055,
"gzip": 16989
},
"ReactARTFiber-dev.js (FB_DEV)": {
"size": 293848,
"gzip": 62755
"size": 293939,
"gzip": 62784
},
"ReactARTFiber-prod.js (FB_PROD)": {
"size": 219245,
Expand All @@ -153,12 +153,12 @@
"gzip": 38548
},
"react-test-renderer.development.js (NODE_DEV)": {
"size": 299343,
"gzip": 63142
"size": 299466,
"gzip": 63178
},
"ReactTestRendererFiber-dev.js (FB_DEV)": {
"size": 298269,
"gzip": 63216
"size": 298392,
"gzip": 63252
},
"react-test-renderer-shallow.development.js (NODE_DEV)": {
"size": 9556,
Expand All @@ -169,8 +169,8 @@
"gzip": 2338
},
"react-noop-renderer.development.js (NODE_DEV)": {
"size": 286618,
"gzip": 60007
"size": 286709,
"gzip": 60040
}
}
}
18 changes: 9 additions & 9 deletions src/renderers/dom/ReactDOMNodeStreamRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,36 @@ class ReactMarkupReadableStream extends Readable {
/**
* Render a ReactElement to its initial HTML. This should only be used on the
* server.
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostream
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertonodestream
*/
function renderToStream(element) {
function renderToNodeStream(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToStream(): Invalid component element.',
'renderToNodeStream(): Invalid component element.',
);
}
return new ReactMarkupReadableStream(element, false);
}

/**
* Similar to renderToStream, except this doesn't create extra DOM attributes
* Similar to renderToNodeStream, except this doesn't create extra DOM attributes
* such as data-react-id that React uses internally.
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostaticstream
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostaticnodestream
*/
function renderToStaticStream(element) {
function renderToStaticNodeStream(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToStaticStream(): Invalid component element.',
'renderToStaticNodeStream(): Invalid component element.',
);
}
return new ReactMarkupReadableStream(element, true);
}

module.exports = {
renderToStream: renderToStream,
renderToStaticStream: renderToStaticStream,
renderToNodeStream: renderToNodeStream,
renderToStaticNodeStream: renderToStaticNodeStream,
};
8 changes: 4 additions & 4 deletions src/renderers/dom/ReactDOMServerBrowserEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ require('ReactDOMInjection');
module.exports = {
renderToString: ReactDOMStringRenderer.renderToString,
renderToStaticMarkup: ReactDOMStringRenderer.renderToStaticMarkup,
renderToStream() {
renderToNodeStream() {
invariant(
false,
'ReactDOMServer.renderToStream(): The streaming API is not available ' +
'ReactDOMServer.renderToNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToString() instead.',
);
},
renderToStaticStream() {
renderToStaticNodeStream() {
invariant(
false,
'ReactDOMServer.renderToStaticStream(): The streaming API is not available ' +
'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.',
);
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/dom/ReactDOMServerNodeEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require('ReactDOMInjection');
module.exports = {
renderToString: ReactDOMStringRenderer.renderToString,
renderToStaticMarkup: ReactDOMStringRenderer.renderToStaticMarkup,
renderToStream: ReactDOMNodeStreamRenderer.renderToStream,
renderToStaticStream: ReactDOMNodeStreamRenderer.renderToStaticStream,
renderToNodeStream: ReactDOMNodeStreamRenderer.renderToNodeStream,
renderToStaticNodeStream: ReactDOMNodeStreamRenderer.renderToStaticNodeStream,
version: ReactVersion,
};
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function renderIntoStream(reactElement, errorCount = 0) {
() =>
new Promise(resolve => {
let writable = new DrainWritable();
ReactDOMServer.renderToStream(reactElement).pipe(writable);
ReactDOMServer.renderToNodeStream(reactElement).pipe(writable);
writable.on('finish', () => resolve(writable.buffer));
}),
errorCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ describe('ReactServerRenderingBrowser', () => {

if (ReactDOMFeatureFlags.useFiber) {
it('throws meaningfully for server-only APIs', () => {
expect(() => ReactDOMServerBrowser.renderToStream(<div />)).toThrow(
'ReactDOMServer.renderToStream(): The streaming API is not available ' +
expect(() => ReactDOMServerBrowser.renderToNodeStream(<div />)).toThrow(
'ReactDOMServer.renderToNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToString() instead.',
);
expect(() => ReactDOMServerBrowser.renderToStaticStream(<div />)).toThrow(
'ReactDOMServer.renderToStaticStream(): The streaming API is not available ' +
expect(() =>
ReactDOMServerBrowser.renderToStaticNodeStream(<div />),
).toThrow(
'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.',
);
});
Expand Down