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
This commit is contained in:
Josh Story
2024-04-23 13:37:49 -04:00
committed by Andrew Clark
parent 415ee0e6ea
commit 7548c019ce
2 changed files with 22 additions and 5 deletions
@@ -620,17 +620,27 @@ describe('ReactDOMServer', () => {
describe('renderToStaticNodeStream', () => {
it('should generate simple markup', () => {
const SuccessfulElement = React.createElement(() => <img />);
const response = ReactDOMServer.renderToStaticNodeStream(
SuccessfulElement,
);
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
expect(() => {
const response = ReactDOMServer.renderToStaticNodeStream(
SuccessfulElement,
);
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
withoutStack: true,
});
});
it('should handle errors correctly', () => {
const FailingElement = React.createElement(() => {
throw new Error('An Error');
});
const response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
let response;
expect(() => {
response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
}).toErrorDev('ReactDOMServer.renderToStaticNodeStream() is deprecated', {
withoutStack: true,
});
return new Promise(resolve => {
response.once('error', () => {
resolve();
@@ -100,6 +100,13 @@ function renderToStaticNodeStream(
children: ReactNodeList,
options?: ServerOptions,
): Readable {
if (__DEV__) {
console.error(
'ReactDOMServer.renderToStaticNodeStream() is deprecated.' +
' Use ReactDOMServer.renderToPipeableStream() and wait to `pipe` until the `onAllReady`' +
' callback has been called instead.',
);
}
return renderToNodeStreamImpl(children, options, true);
}