From c47fee55d9886b2d9746a4b71c48bbd8b8ac9d3a Mon Sep 17 00:00:00 2001 From: Josh Story Date: Thu, 21 Mar 2024 11:03:09 -0700 Subject: [PATCH] [Fizz][Legacy] use static markup mode for renderToStaticNodeStream (#28606) Since it was first implemented renderToStaticNodeStream never correctly set the renderer state to mark the output as static markup which means it was functionally the same as renderToNodeStream. This change fixes this oversight. While we are removing renderToNodeStream in a future version we never did deprecate the static version of this API because it has no immediate analog in the modern APIs. --- .../__tests__/ReactServerRendering-test.js | 59 ++++++++++++++----- .../server/ReactDOMLegacyServerNodeStream.js | 2 +- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js index 07654a9f13c0a..ec962ef8ba52c 100644 --- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js @@ -609,6 +609,41 @@ describe('ReactDOMServer', () => { expect(response.read()).toBeNull(); }); }); + + it('should refer users to new apis when using suspense', async () => { + let resolve = null; + const promise = new Promise(res => { + resolve = () => { + resolved = true; + res(); + }; + }); + let resolved = false; + function Suspender() { + if (resolved) { + return 'resolved'; + } + throw promise; + } + + let response; + expect(() => { + response = ReactDOMServer.renderToNodeStream( +
+ + + +
, + ); + }).toErrorDev( + 'renderToNodeStream is deprecated. Use renderToPipeableStream instead.', + {withoutStack: true}, + ); + await resolve(); + expect(response.read().toString()).toEqual( + '
resolved
', + ); + }); }); describe('renderToStaticNodeStream', () => { @@ -632,7 +667,7 @@ describe('ReactDOMServer', () => { }); }); - it('should refer users to new apis when using suspense', async () => { + it('should omit text and suspense placeholders', async () => { let resolve = null; const promise = new Promise(res => { resolve = () => { @@ -648,23 +683,15 @@ describe('ReactDOMServer', () => { throw promise; } - let response; - expect(() => { - response = ReactDOMServer.renderToNodeStream( -
- - - -
, - ); - }).toErrorDev( - 'renderToNodeStream is deprecated. Use renderToPipeableStream instead.', - {withoutStack: true}, + const response = ReactDOMServer.renderToStaticNodeStream( +
+ + + +
, ); await resolve(); - expect(response.read().toString()).toEqual( - '
resolved
', - ); + expect(response.read().toString()).toEqual('
resolved
'); }); }); diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.js b/packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.js index 8df44d8004261..16090d9035668 100644 --- a/packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.js +++ b/packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.js @@ -78,7 +78,7 @@ function renderToNodeStreamImpl( const request = createRequest( children, resumableState, - createRenderState(resumableState, false), + createRenderState(resumableState, generateStaticMarkup), createRootFormatContext(), Infinity, onError,