Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/react-server/src/ReactFlightReplyServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,9 @@ function createMap(
if ((model as any).$$consumed === true) {
throw new Error('Already initialized Map.');
}
const map = new Map(model);
// This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
(model as any).$$consumed = true;
const map = new Map(model);
return map;
}

Expand All @@ -1135,8 +1136,9 @@ function createSet(response: Response, model: Array<any>): Set<any> {
if ((model as any).$$consumed === true) {
throw new Error('Already initialized Set.');
}
const set = new Set(model);
// This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
(model as any).$$consumed = true;
const set = new Set(model);
return set;
}

Expand All @@ -1147,9 +1149,10 @@ function extractIterator(response: Response, model: Array<any>): Iterator<any> {
if ((model as any).$$consumed === true) {
throw new Error('Already initialized Iterator.');
}
// This needs to come first to prevent the model from being consumed again in case of a cyclic reference.
(model as any).$$consumed = true;
// $FlowFixMe[incompatible-use]: This uses raw Symbols because we're extracting from a native array.
const iterator = model[Symbol.iterator]();
(model as any).$$consumed = true;
return iterator;
}

Expand Down
Loading