{"record":{"id":"5c61500f9201b7d2","repo":"facebook/react","slug":"573","errorCode":"573","errorMessage":"Already initialized Set.","messagePattern":"Already initialized Set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server/src/ReactFlightReplyServer.js","lineNumber":1193,"sourceCode":"): Map<any, any> {\n  if (!isArray(model)) {\n    throw new Error('Invalid Map initializer.');\n  }\n  if ((model as any).$$consumed === true) {\n    throw new Error('Already initialized Map.');\n  }\n  // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.\n  (model as any).$$consumed = true;\n  const map = new Map(model);\n  return map;\n}\n\nfunction createSet(response: Response, model: Array<any>): Set<any> {\n  if (!isArray(model)) {\n    throw new Error('Invalid Set initializer.');\n  }\n  if ((model as any).$$consumed === true) {\n    throw new Error('Already initialized Set.');\n  }\n  // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.\n  (model as any).$$consumed = true;\n  const set = new Set(model);\n  return set;\n}\n\nfunction extractIterator(response: Response, model: Array<any>): Iterator<any> {\n  if (!isArray(model)) {\n    throw new Error('Invalid Iterator initializer.');\n  }\n  if ((model as any).$$consumed === true) {\n    throw new Error('Already initialized Iterator.');\n  }\n  // This needs to come first to prevent the model from being consumed again in case of a cyclic reference.\n  (model as any).$$consumed = true;\n  // $FlowFixMe[incompatible-use]: This uses raw Symbols because we're extracting from a native array.\n  const iterator = model[Symbol.iterator]();","sourceCodeStart":1175,"sourceCodeEnd":1211,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server/src/ReactFlightReplyServer.js#L1175-L1211","documentation":"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.","triggerScenarios":"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.","commonSituations":"Self-referential Sets passed through server actions; replayed or edited FormData referencing one Set model from multiple positions.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function hasCycle(v: unknown, seen = new WeakSet()): boolean {\n  if (v && (typeof v === 'object' || typeof v === 'function')) {\n    if (seen.has(v)) return true;\n    seen.add(v);\n    if (v instanceof Set) {\n      for (const item of v) if (hasCycle(item, seen)) return true;\n    }\n  }\n  return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const args = await decodeReply(formData);\n} catch (e) {\n  return new Response('Bad request', {status: 400});\n}","preventionTips":["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."],"tags":["react","server-actions","deserialization","set","cyclic-reference"],"backgroundTag":"cyclic-reference-in-serialized-data","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}