@@ -543,6 +543,55 @@ describe('ReactFlightDOMEdge', () => {
543543 expect ( await iterator . next ( ) ) . toEqual ( { value : undefined , done : true } ) ;
544544 } ) ;
545545
546+ // @gate enableFlightReadableStream
547+ it ( 'dedupes objects inside async iterables' , async ( ) => {
548+ const obj = {
549+ this : { is : 'a large objected' } ,
550+ with : { many : 'properties in it' } ,
551+ } ;
552+ const iterable = {
553+ async * [ Symbol . asyncIterator ] ( ) {
554+ for ( let i = 0 ; i < 30 ; i ++ ) {
555+ yield obj ;
556+ }
557+ } ,
558+ } ;
559+
560+ const stream = ReactServerDOMServer . renderToReadableStream ( {
561+ iterable,
562+ } ) ;
563+ const [ stream1 , stream2 ] = passThrough ( stream ) . tee ( ) ;
564+
565+ const serializedContent = await readResult ( stream1 ) ;
566+ // TODO: Ideally streams should dedupe objects but because we never outline the objects
567+ // they end up not having a row to reference them nor any of its nested objects.
568+ // expect(serializedContent.length).toBeLessThan(400);
569+ expect ( serializedContent . length ) . toBeMoreThan ( 400 ) ;
570+
571+ const result = await ReactServerDOMClient . createFromReadableStream (
572+ stream2 ,
573+ {
574+ ssrManifest : {
575+ moduleMap : null ,
576+ moduleLoading : null ,
577+ } ,
578+ } ,
579+ ) ;
580+
581+ const items = [ ] ;
582+ const iterator = result . iterable [ Symbol . asyncIterator ] ( ) ;
583+ let entry ;
584+ while ( ! ( entry = await iterator . next ( ) ) . done ) {
585+ items . push ( entry . value ) ;
586+ }
587+
588+ // Should still match the result when parsed
589+ expect ( items . length ) . toBe ( 30 ) ;
590+ // TODO: These should be the same
591+ // expect(items[5]).toBe(items[10]); // two random items are the same instance
592+ expect ( items [ 5 ] ) . toEqual ( items [ 10 ] ) ;
593+ } ) ;
594+
546595 it ( 'warns if passing a this argument to bind() of a server reference' , async ( ) => {
547596 const ServerModule = serverExports ( {
548597 greet : function ( ) { } ,
0 commit comments