facebook/react · error · Error
572
572
Error message
Already initialized Map.
What it means
createMap sets $$consumed = true on the model array before building the Map, specifically so a cyclic reference cannot consume the same model twice. If the same serialized Map model reaches createMap again, the guard throws instead of producing wrong data or looping.
Solutions
- Avoid passing self-referential/cyclic Maps as server action arguments; reference members by id instead.
- Catch the decode error and reject the request as malformed.
- Align React versions across the boundary if skew is suspected.
Example fix
// before
const m = new Map();
m.set('self', m); // cyclic Map serialized into a self-referencing model
await save(m);
// after
const m = new Map();
m.set('rootId', 'map-1'); // reference by identifier, resolve on the server
await save({id: 'map-1', entries: [...m]}); 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 Map) {
for (const [k, val] of v) if (hasCycle(k, seen) || hasCycle(val, seen)) return true;
} else if (v instanceof Set) {
for (const item of v) if (hasCycle(item, seen)) return true;
} else if (Array.isArray(v)) {
for (const item of v) if (hasCycle(item, seen)) return true;
} else {
for (const k in v) if (hasCycle((v as any)[k], seen)) return true;
}
}
return false;
}
// before invoking the action
if (hasCycle(args)) throw new Error('Cyclic data cannot be serialized'); Try / catch
try {
const args = await decodeReply(formData);
} catch (e) {
return new Response('Bad request', {status: 400});
} Prevention
- Do not pass self-referential Maps as server action arguments; reference members by id.
- Run a cycle check on complex client state before submitting it to an action.
- Rebuild cyclic structures server-side from flat records.
When it happens
Trigger: The same Map model is initialized twice - a cyclic structure the encoder failed to outline (a Map containing itself), duplicate references to one model in a crafted payload, or version-skewed encoders.
Common situations: Passing self-referential Maps through server actions; replayed or edited FormData where one Map id is referenced from two initializer positions.
Related errors
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/d0b427a8860de664.
Report an issue: GitHub.
Appendix: source
Thrown at packages/react-server/src/ReactFlightReplyServer.js:1180
reason: chunk.reason,
deps: 0,
errored: true,
};
}
// Placeholder
return null as any;
}
}
function createMap(
response: Response,
model: Array<[any, any]>,
): 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;View on GitHub (pinned to eafeac097b)