@@ -1123,8 +1123,9 @@ function createMap(
11231123 if ((model as any).$$consumed === true) {
11241124 throw new Error ( 'Already initialized Map.' ) ;
11251125 }
1126- const map = new Map( model);
1126+ // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
11271127 (model as any).$$consumed = true;
1128+ const map = new Map(model);
11281129 return map;
11291130}
11301131
@@ -1135,8 +1136,9 @@ function createSet(response: Response, model: Array<any>): Set<any> {
11351136 if ((model as any).$$consumed === true) {
11361137 throw new Error ( 'Already initialized Set.' ) ;
11371138 }
1138- const set = new Set( model);
1139+ // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
11391140 (model as any).$$consumed = true;
1141+ const set = new Set(model);
11401142 return set;
11411143}
11421144
@@ -1147,9 +1149,10 @@ function extractIterator(response: Response, model: Array<any>): Iterator<any> {
11471149 if ((model as any).$$consumed === true) {
11481150 throw new Error ( 'Already initialized Iterator.' ) ;
11491151 }
1152+ // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
1153+ (model as any).$$consumed = true;
11501154 // $FlowFixMe[incompatible-use]: This uses raw Symbols because we're extracting from a native array.
11511155 const iterator = model[Symbol.iterator]();
1152- (model as any).$$consumed = true;
11531156 return iterator;
11541157}
11551158
0 commit comments