Skip to content

Commit 718e73a

Browse files
committed
Verifying that #28996 makes this change obsolete
1 parent d1a82f8 commit 718e73a

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,4 +2490,76 @@ describe('ReactFlight', () => {
24902490

24912491
expect(ReactNoop).toMatchRenderedOutput(<span>Hello, Seb</span>);
24922492
});
2493+
2494+
// @gate __DEV__
2495+
it('does not emit duplicate chunks for already outlined elements in dev mode', async () => {
2496+
async function Bar({text}) {
2497+
return text.toUpperCase();
2498+
}
2499+
2500+
function Foo() {
2501+
const bar = <Bar text="bar" />;
2502+
2503+
return (
2504+
<div>
2505+
{bar}
2506+
{bar}
2507+
</div>
2508+
);
2509+
}
2510+
2511+
const transport = ReactNoopFlightServer.render(<Foo />);
2512+
const textDecoder = new TextDecoder();
2513+
2514+
await act(async () => {
2515+
const chunks = transport
2516+
.map(chunk => textDecoder.decode(chunk).replace(/\n$/, ''))
2517+
.join('\n');
2518+
2519+
expect(chunks).toEqual(
2520+
`
2521+
1:{"name":"Foo","env":"Server","owner":null}
2522+
0:D"$1"
2523+
3:{"name":"Bar","env":"Server","owner":null}
2524+
2:D"$3"
2525+
0:["$","div",null,{"children":["$L2","$2"]},null]
2526+
2:"BAR"
2527+
`.trim(),
2528+
);
2529+
});
2530+
});
2531+
2532+
// @gate !__DEV__
2533+
it('does not emit duplicate chunks for already outlined elements in production mode', async () => {
2534+
async function Bar({text}) {
2535+
return text.toUpperCase();
2536+
}
2537+
2538+
function Foo() {
2539+
const bar = <Bar text="bar" />;
2540+
2541+
return (
2542+
<div>
2543+
{bar}
2544+
{bar}
2545+
</div>
2546+
);
2547+
}
2548+
2549+
const transport = ReactNoopFlightServer.render(<Foo />);
2550+
const textDecoder = new TextDecoder();
2551+
2552+
await act(async () => {
2553+
const chunks = transport
2554+
.map(chunk => textDecoder.decode(chunk).replace(/\n$/, ''))
2555+
.join('\n');
2556+
2557+
expect(chunks).toEqual(
2558+
`
2559+
0:["$","div",null,{"children":["$L1","$0:props:children:0"]}]
2560+
1:"BAR"
2561+
`.trim(),
2562+
);
2563+
});
2564+
});
24932565
});

packages/react-server/src/ReactFlightServer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,9 @@ function renderModel(
16491649
task.implicitSlot,
16501650
request.abortableTasks,
16511651
);
1652+
// The suspended element was outlined, so we're using the same ID for the
1653+
// original value, thus ensuring that it's deduplicated if it's referenced again.
1654+
// request.writtenObjects.set((value: any), newTask.id);
16521655
const ping = newTask.ping;
16531656
(x: any).then(ping, ping);
16541657
newTask.thenableState = getThenableStateAfterSuspending();

0 commit comments

Comments
 (0)