Skip to content

Commit 1d38832

Browse files
committed
Add another test for resolving of deduped props
1 parent 1e4159e commit 1d38832

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ describe('ReactFlightDOMBrowser', () => {
525525
expect(container.innerHTML).toBe('{"foo":1}{"foo":1}');
526526
});
527527

528-
it('should handle deduped props of elements in fragments', async () => {
528+
it('should handle deduped props of re-used elements in fragments (same-chunk reference)', async () => {
529529
let resolveFooClientComponentChunk;
530530

531531
const FooClient = clientExports(
@@ -542,7 +542,58 @@ describe('ReactFlightDOMBrowser', () => {
542542
function Server() {
543543
return (
544544
<FooClient track={shared}>
545-
<React.Fragment>{shared}</React.Fragment>
545+
<>{shared}</>
546+
</FooClient>
547+
);
548+
}
549+
550+
const stream = await serverAct(() =>
551+
ReactServerDOMServer.renderToReadableStream(<Server />, webpackMap),
552+
);
553+
554+
function ClientRoot({response}) {
555+
return use(response);
556+
}
557+
558+
const response = ReactServerDOMClient.createFromReadableStream(stream);
559+
const container = document.createElement('div');
560+
const root = ReactDOMClient.createRoot(container);
561+
562+
await act(() => {
563+
root.render(<ClientRoot response={response} />);
564+
});
565+
566+
expect(container.innerHTML).toBe('');
567+
568+
await act(() => {
569+
resolveFooClientComponentChunk();
570+
});
571+
572+
expect(container.innerHTML).toBe('<div></div>');
573+
});
574+
575+
it('should handle deduped props of re-used elements in server components (cross-chunk reference)', async () => {
576+
let resolveFooClientComponentChunk;
577+
578+
function PassthroughServerComponent({children}) {
579+
return children;
580+
}
581+
582+
const FooClient = clientExports(
583+
function Foo({children, item}) {
584+
return children;
585+
},
586+
'1',
587+
'/foo.js',
588+
new Promise(resolve => (resolveFooClientComponentChunk = resolve)),
589+
);
590+
591+
const shared = <div />;
592+
593+
function Server() {
594+
return (
595+
<FooClient track={shared}>
596+
<PassthroughServerComponent>{shared}</PassthroughServerComponent>
546597
</FooClient>
547598
);
548599
}

0 commit comments

Comments
 (0)