Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fizz][Legacy] use static markup mode for renderToStaticNodeStream #28606

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test already existed it was just in the wrong describe block. It now correctly lives in the renderToNodeStream block

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 () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is now asserting the removal of hydration markup even though I kept the test form largely intact

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