Skip to content

Commit

Permalink
[Fizz][Legacy] use static markup mode for renderToStaticNodeStream (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
gnoff authored Mar 21, 2024
1 parent 7263b4f commit c47fee5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
59 changes: 43 additions & 16 deletions packages/react-dom/src/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<div>
<React.Suspense fallback={'fallback'}>
<Suspender />
</React.Suspense>
</div>,
);
}).toErrorDev(
'renderToNodeStream is deprecated. Use renderToPipeableStream instead.',
{withoutStack: true},
);
await resolve();
expect(response.read().toString()).toEqual(
'<div><!--$-->resolved<!-- --><!--/$--></div>',
);
});
});

describe('renderToStaticNodeStream', () => {
Expand All @@ -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 = () => {
Expand All @@ -648,23 +683,15 @@ describe('ReactDOMServer', () => {
throw promise;
}

let response;
expect(() => {
response = ReactDOMServer.renderToNodeStream(
<div>
<React.Suspense fallback={'fallback'}>
<Suspender />
</React.Suspense>
</div>,
);
}).toErrorDev(
'renderToNodeStream is deprecated. Use renderToPipeableStream instead.',
{withoutStack: true},
const response = ReactDOMServer.renderToStaticNodeStream(
<div>
<React.Suspense fallback={'fallback'}>
<Suspender />
</React.Suspense>
</div>,
);
await resolve();
expect(response.read().toString()).toEqual(
'<div><!--$-->resolved<!-- --><!--/$--></div>',
);
expect(response.read().toString()).toEqual('<div>resolved</div>');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function renderToNodeStreamImpl(
const request = createRequest(
children,
resumableState,
createRenderState(resumableState, false),
createRenderState(resumableState, generateStaticMarkup),
createRootFormatContext(),
Infinity,
onError,
Expand Down

0 comments on commit c47fee5

Please sign in to comment.