@@ -79,6 +79,7 @@ export type Request = {
7979 completedModuleChunks : Array < Chunk > ,
8080 completedJSONChunks : Array < Chunk > ,
8181 completedErrorChunks : Array < Chunk > ,
82+ writtenSymbols : Map < Symbol , number> ,
8283 flowing : boolean ,
8384 toJSON : ( key : string , value : ReactModel ) => ReactJSONValue ,
8485} ;
@@ -100,6 +101,7 @@ export function createRequest(
100101 completedModuleChunks : [ ] ,
101102 completedJSONChunks : [ ] ,
102103 completedErrorChunks : [ ] ,
104+ writtenSymbols : new Map ( ) ,
103105 flowing : false ,
104106 toJSON : function ( key : string , value : ReactModel ) : ReactJSONValue {
105107 return resolveModelToJSON ( request , this , key , value ) ;
@@ -528,9 +530,15 @@ export function resolveModelToJSON(
528530 describeKeyForErrorMessage ( key ) ,
529531 describeObjectForErrorMessage ( parent ) ,
530532 ) ;
533+ const writtenSymbols = request . writtenSymbols ;
534+ const existingId = writtenSymbols . get ( value ) ;
535+ if ( existingId !== undefined ) {
536+ return serializeByValueID ( existingId ) ;
537+ }
531538 request . pendingChunks ++ ;
532539 const symbolId = request . nextChunkId ++ ;
533540 emitSymbolChunk ( request , symbolId , name ) ;
541+ writtenSymbols . set ( value , symbolId ) ;
534542 return serializeByValueID ( symbolId ) ;
535543 }
536544
0 commit comments