@@ -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} ) ;
0 commit comments