facebook/react · error · Error

578

578

Error message

Already initialized Iterator.

What it means

extractIterator sets $$consumed = true on the model array before creating the iterator so cyclic references cannot consume it twice. If the same model reaches extractIterator again, the guard throws.

Solutions

  1. Avoid passing iterators of cyclic structures as action arguments; send materialized arrays or ids instead.
  2. Catch the error during decode and reject the request as malformed.
  3. Align React versions across the boundary.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const args = await decodeReply(formData);
} catch (e) {
  return new Response('Bad request', {status: 400});
}

Prevention

When it happens

Trigger: The same serialized iterator model is initialized twice - cyclic structures not outlined by the encoder, duplicate references in a crafted payload, or version-skewed wire formats.

Common situations: Iterators over self-referential data passed to server actions; replayed or hand-edited FormData.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/c680dec3de40e2ee. Report an issue: GitHub.

Appendix: source

Thrown at packages/react-server/src/ReactFlightReplyServer.js:1206

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]();
  return iterator;
}

function createModel(
  response: Response,
  model: any,
  parentObject: Object,
  key: string,
): any {
  if (key === 'then' && typeof model === 'function') {
    // This should never happen because we always serialize objects with then-functions
    // as "thenable" which reduces to ReactPromise with no other fields.
    return null;

View on GitHub (pinned to eafeac097b)