facebook/react · error · Error
573
573
Error message
Already initialized Set.
What it means
createSet marks the model array with $$consumed = true before building the Set so a cyclic reference cannot consume it twice. A second initialization attempt on the same model trips the guard and throws.
Source
Thrown at packages/react-server/src/ReactFlightReplyServer.js:1193
): Map<any, any> {
if (!isArray(model)) {
throw new Error('Invalid Map initializer.');
}
if ((model as any).$$consumed === true) {
throw new Error('Already initialized Map.');
}
// 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;
}
function createSet(response: Response, model: Array<any>): Set<any> {
if (!isArray(model)) {
throw new Error('Invalid Set initializer.');
}
if ((model as any).$$consumed === true) {
throw new Error('Already initialized Set.');
}
// 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;
}
function extractIterator(response: Response, model: Array<any>): Iterator<any> {
if (!isArray(model)) {
throw new Error('Invalid Iterator initializer.');
}
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]();View on GitHub (pinned to eafeac097b)
Solutions
- Do not pass self-referential Sets as action arguments; use ids and rebuild the structure server-side.
- Reject the request via a catch around decodeReply.
- Align React versions if the payload came from a stale bundle.
Defensive patterns
Strategy: try-catch
Validate before calling
function hasCycle(v: unknown, seen = new WeakSet()): boolean {
if (v && (typeof v === 'object' || typeof v === 'function')) {
if (seen.has(v)) return true;
seen.add(v);
if (v instanceof Set) {
for (const item of v) if (hasCycle(item, seen)) return true;
}
}
return false;
} Try / catch
try {
const args = await decodeReply(formData);
} catch (e) {
return new Response('Bad request', {status: 400});
} Prevention
- Avoid self-referential Sets in action arguments; send materialized entry lists.
- Check client state for cycles before serializing it into a submission.
- Map decode failures to 400 and log the source of the payload.
When it happens
Trigger: The same serialized Set model is initialized twice - cyclic data the encoder did not outline (a Set containing itself), duplicate references within a crafted payload, or version-skewed encoding.
Common situations: Self-referential Sets passed through server actions; replayed or edited FormData referencing one Set model from multiple positions.
Related errors
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/5c61500f9201b7d2.
Report an issue: GitHub.