{"record":{"id":"edeef511442df16f","repo":"react/react","slug":"values-cannot-be-passed-to-next-of-asynciterable","errorCode":null,"errorMessage":"Values cannot be passed to next() of AsyncIterables passed to Client Components.","messagePattern":"Values cannot be passed to next\\(\\) of AsyncIterables passed to Client Components\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-client/src/ReactFlightClient.js","lineNumber":3604,"sourceCode":"      }\n      closed = true;\n      if (nextWriteIndex === buffer.length) {\n        buffer[nextWriteIndex] =\n          createPendingChunk<IteratorResult<T, T>>(response);\n      }\n      while (nextWriteIndex < buffer.length) {\n        triggerErrorOnChunk(response, buffer[nextWriteIndex++], error);\n      }\n    },\n  };\n\n  const iterable: $AsyncIterable<T, T, void> = {} as any;\n  // $FlowFixMe[cannot-write]\n  iterable[ASYNC_ITERATOR] = (): $AsyncIterator<T, T, void> => {\n    let nextReadIndex = 0;\n    return createIterator(arg => {\n      if (arg !== undefined) {\n        throw new Error(\n          'Values cannot be passed to next() of AsyncIterables passed to Client Components.',\n        );\n      }\n      if (nextReadIndex === buffer.length) {\n        if (closed) {\n          // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors\n          return new ReactPromise(\n            INITIALIZED,\n            {done: true, value: undefined},\n            null,\n          );\n        }\n        buffer[nextReadIndex] =\n          createPendingChunk<IteratorResult<T, T>>(response);\n      }\n      return buffer[nextReadIndex++];\n    });\n  };","sourceCodeStart":3586,"sourceCodeEnd":3622,"githubUrl":"https://github.com/react/react/blob/22e4f993c7ce9373c95aef093b003f84249e2045/packages/react-client/src/ReactFlightClient.js#L3586-L3622","documentation":"When an AsyncIterable crosses the server-to-client boundary over Flight, React reconstructs it as a read-only stream and gives its iterator a `next()` that ignores arguments. Passing any argument to `next(arg)` is meaningless because the server side cannot receive it, so React throws to surface the misuse immediately. The iterable is intentionally argument-less; it is not a generic communication channel back to the server.","triggerScenarios":"Consuming an AsyncIterable returned from a Server Component via a `for await` loop is fine; the error only occurs when code manually calls `iter.next(someValue)` (or a helper that forwards a value) on the reconstructed client iterable. Common with custom stream consumers, generators that pass values into `next()`, or libraries that treat the iterator as two-way.","commonSituations":"Passing the server-originated stream into a generator-combinator (e.g. iterating with an explicit `await it.next(input)`). Migrating a local two-way async generator to one received from the server without realizing the client copy is read-only.","solutions":["Remove the argument: call `await iter.next()` (or just use `for await (const v of iterable)`).","If you genuinely need to send values back to the server, use a Server Action argument instead of the iterable's next().","Wrap the iterable in your own local generator if you need value-passing semantics locally, but never pass values into the Flight-provided iterator."],"exampleFix":"// before\nconst it = serverStream[Symbol.asyncIterator]();\nconst {value} = await it.next('resume'); // throws\n\n// after\nconst {value} = await it.next(); // no argument","handlingStrategy":"validation","validationCode":"// Wrap consumption so an accidental argument is rejected up front.\nasync function drain(iterable) {\n  const it = iterable[Symbol.asyncIterator]();\n  // Always call next() with no args.\n  for (;;) {\n    const {value, done} = await it.next();\n    if (done) return value;\n    handleChunk(value);\n  }\n}","typeGuard":"function isFlightIterable(value) {\n  return value != null && typeof value[Symbol.asyncIterator] === 'function';\n}\n// Note: there is no public marker to distinguish a server-originated iterable;\n// treat all such iterables as read-only.","tryCatchPattern":"try {\n  await drain(serverIterable);\n} catch (e) {\n  if (e?.message?.includes('Values cannot be passed to next()')) {\n    console.error('Do not pass arguments to next() of a server-originated iterable.');\n  }\n  throw e;\n}","preventionTips":["Prefer `for await (const v of iterable)` over manual `next()` calls.","Never forward values into next() of an iterable you did not create locally.","Document server-originated iterables as read-only in your codebase."],"tags":["react-server-components","async-iterable","flight","api-misuse"],"backgroundTag":null,"analyzedSha":"22e4f993c7ce9373c95aef093b003f84249e2045","analyzedAt":"2026-08-12T22:33:25.580Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}