@@ -78,6 +78,7 @@ export type Request = {
78
78
completedModuleChunks : Array < Chunk > ,
79
79
completedJSONChunks : Array < Chunk > ,
80
80
completedErrorChunks : Array < Chunk > ,
81
+ writtenSymbols : Map < Symbol , number> ,
81
82
flowing : boolean ,
82
83
toJSON : ( key : string , value : ReactModel ) => ReactJSONValue ,
83
84
} ;
@@ -99,6 +100,7 @@ export function createRequest(
99
100
completedModuleChunks : [ ] ,
100
101
completedJSONChunks : [ ] ,
101
102
completedErrorChunks : [ ] ,
103
+ writtenSymbols : new Map ( ) ,
102
104
flowing : false ,
103
105
toJSON : function ( key : string , value : ReactModel ) : ReactJSONValue {
104
106
return resolveModelToJSON ( request , this , key , value ) ;
@@ -527,9 +529,15 @@ export function resolveModelToJSON(
527
529
describeKeyForErrorMessage ( key ) ,
528
530
describeObjectForErrorMessage ( parent ) ,
529
531
) ;
532
+ const writtenSymbols = request . writtenSymbols ;
533
+ const existingId = writtenSymbols . get ( value ) ;
534
+ if ( existingId !== undefined ) {
535
+ return serializeByValueID ( existingId ) ;
536
+ }
530
537
request . pendingChunks ++ ;
531
538
const symbolId = request . nextChunkId ++ ;
532
539
emitSymbolChunk ( request , symbolId , name ) ;
540
+ writtenSymbols . set ( value , symbolId ) ;
533
541
return serializeByValueID ( symbolId ) ;
534
542
}
535
543
0 commit comments