Skip to content

Commit 0d4e24b

Browse files
committed
Deprecate renderToStaticNodeStream (facebook#28872)
This commit adds warnings indicating that `renderToStaticNodeStream` will be removed in an upcoming React release. This API has been legacy, is not widely used (renderToStaticMarkup is more common) and has semantically eqiuvalent implementations with renderToReadableStream and renderToPipeableStream.
1 parent 415ee0e commit 0d4e24b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

packages/react-dom/src/__tests__/ReactServerRendering-test.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,17 +620,26 @@ describe('ReactDOMServer', () => {
620620
describe('renderToStaticNodeStream', () => {
621621
it('should generate simple markup', () => {
622622
const SuccessfulElement = React.createElement(() => <img />);
623-
const response = ReactDOMServer.renderToStaticNodeStream(
624-
SuccessfulElement,
625-
);
626-
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
623+
expect(() => {
624+
const response =
625+
ReactDOMServer.renderToStaticNodeStream(SuccessfulElement);
626+
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
627+
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
628+
withoutStack: true,
629+
});
627630
});
628631

629632
it('should handle errors correctly', () => {
630633
const FailingElement = React.createElement(() => {
631634
throw new Error('An Error');
632635
});
633-
const response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
636+
637+
let response;
638+
expect(() => {
639+
response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
640+
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
641+
withoutStack: true,
642+
});
634643
return new Promise(resolve => {
635644
response.once('error', () => {
636645
resolve();
@@ -689,9 +698,7 @@ describe('ReactDOMServer', () => {
689698
}
690699

691700
ReactDOMServer.renderToString(<Foo />);
692-
expect(() =>
693-
jest.runOnlyPendingTimers(),
694-
).toErrorDev(
701+
expect(() => jest.runOnlyPendingTimers()).toErrorDev(
695702
'Warning: setState(...): Can only update a mounting component.' +
696703
' This usually means you called setState() outside componentWillMount() on the server.' +
697704
' This is a no-op.\n\nPlease check the code for the Foo component.',
@@ -719,9 +726,7 @@ describe('ReactDOMServer', () => {
719726
}
720727

721728
ReactDOMServer.renderToString(<Baz />);
722-
expect(() =>
723-
jest.runOnlyPendingTimers(),
724-
).toErrorDev(
729+
expect(() => jest.runOnlyPendingTimers()).toErrorDev(
725730
'Warning: forceUpdate(...): Can only update a mounting component. ' +
726731
'This usually means you called forceUpdate() outside componentWillMount() on the server. ' +
727732
'This is a no-op.\n\nPlease check the code for the Baz component.',

packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ function renderToStaticNodeStream(
100100
children: ReactNodeList,
101101
options?: ServerOptions,
102102
): Readable {
103+
if (__DEV__) {
104+
console.error(
105+
'ReactDOMServer.renderToStaticNodeStream() is deprecated.' +
106+
' Use ReactDOMServer.renderToPipeableStream() and wait to `pipe` until the `onAllReady`' +
107+
' callback has been called instead.',
108+
);
109+
}
103110
return renderToNodeStreamImpl(children, options, true);
104111
}
105112

0 commit comments

Comments
 (0)