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

[Flight] Support Keyed Server Components #28123

Merged
merged 7 commits into from
Feb 5, 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
425 changes: 425 additions & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,55 @@ describe('ReactFlightDOMEdge', () => {
const [stream1, stream2] = passThrough(stream).tee();

const serializedContent = await readResult(stream1);

expect(serializedContent.length).toBeLessThan(400);
expect(timesRendered).toBeLessThan(5);

const result = await ReactServerDOMClient.createFromReadableStream(
stream2,
{
ssrManifest: {
moduleMap: null,
moduleLoading: null,
},
const model = await ReactServerDOMClient.createFromReadableStream(stream2, {
ssrManifest: {
moduleMap: null,
moduleLoading: null,
},
});

// Use the SSR render to resolve any lazy elements
const ssrStream = await ReactDOMServer.renderToReadableStream(model);
// Should still match the result when parsed
const result = await readResult(ssrStream);
expect(result).toEqual(resolvedChildren.join('<!-- -->'));
});

it('should execute repeated host components only once', async () => {
const div = <div>this is a long return value</div>;
let timesRendered = 0;
function ServerComponent() {
timesRendered++;
return div;
}
const element = <ServerComponent />;
const children = new Array(30).fill(element);
const resolvedChildren = new Array(30).fill(
'<div>this is a long return value</div>',
);
const stream = ReactServerDOMServer.renderToReadableStream(children);
const [stream1, stream2] = passThrough(stream).tee();

const serializedContent = await readResult(stream1);
expect(serializedContent.length).toBeLessThan(400);
expect(timesRendered).toBeLessThan(5);

const model = await ReactServerDOMClient.createFromReadableStream(stream2, {
ssrManifest: {
moduleMap: null,
moduleLoading: null,
},
});

// Use the SSR render to resolve any lazy elements
const ssrStream = await ReactDOMServer.renderToReadableStream(model);
// Should still match the result when parsed
expect(result).toEqual(resolvedChildren);
const result = await readResult(ssrStream);
expect(result).toEqual(resolvedChildren.join(''));
});

it('should execute repeated server components in a compact form', async () => {
Expand Down
Loading