Skip to content

Commit 7548c01

Browse files
gnoffacdlite
authored andcommitted
Deprecate renderToStaticNodeStream (#28872) (#28874)
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. landed in main in #28872 changed the warning to match renderToNodeStream
1 parent 415ee0e commit 7548c01

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,17 +620,27 @@ 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 = ReactDOMServer.renderToStaticNodeStream(
625+
SuccessfulElement,
626+
);
627+
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
628+
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
629+
withoutStack: true,
630+
});
627631
});
628632

629633
it('should handle errors correctly', () => {
630634
const FailingElement = React.createElement(() => {
631635
throw new Error('An Error');
632636
});
633-
const response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
637+
638+
let response;
639+
expect(() => {
640+
response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
641+
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
642+
withoutStack: true,
643+
});
634644
return new Promise(resolve => {
635645
response.once('error', () => {
636646
resolve();

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)