{"record":{"id":"9618c72c67eb82c5","repo":"facebook/react","slug":"while-flushing-work-something-yielded-a-value-us","errorCode":null,"errorMessage":"While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])","messagePattern":"While flushing work, something yielded a value\\. Use an assertion helper to assert on the log of yielded values, e\\.g\\. expect\\(Scheduler\\)\\.toFlushAndYield\\(\\[\\.\\.\\.\\]\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/scheduler/src/forks/SchedulerMock.js","lineNumber":619,"sourceCode":"function unstable_clearLog(): Array<mixed> {\n  if (yieldedValues === null) {\n    return [];\n  }\n  const values = yieldedValues;\n  yieldedValues = null;\n  return values;\n}\n\nfunction unstable_flushAll(): void {\n  if (yieldedValues !== null) {\n    throw new Error(\n      'Log is not empty. Assert on the log of yielded values before ' +\n        'flushing additional work.',\n    );\n  }\n  unstable_flushAllWithoutAsserting();\n  if (yieldedValues !== null) {\n    throw new Error(\n      'While flushing work, something yielded a value. Use an ' +\n        'assertion helper to assert on the log of yielded values, e.g. ' +\n        'expect(Scheduler).toFlushAndYield([...])',\n    );\n  }\n}\n\nfunction log(value: mixed): void {\n  // eslint-disable-next-line react-internal/no-production-logging\n  if (console.log.name === 'disabledLog' || disableYieldValue) {\n    // If console.log has been patched, we assume we're in render\n    // replaying and we ignore any values yielding in the second pass.\n    return;\n  }\n  if (yieldedValues === null) {\n    yieldedValues = [value];\n  } else {\n    yieldedValues.push(value);","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/scheduler/src/forks/SchedulerMock.js#L601-L637","documentation":"unstable_flushAll() re-checks the yielded-value log after draining all queued work; if any task called Scheduler.log(value) during the flush it throws 'While flushing work, something yielded a value...'. The mock insists that tests which produce logged values declare them via an assertion helper such as expect(Scheduler).toFlushAndYield([...]) instead of a bare flush that would silently discard them.","triggerScenarios":"Calling Scheduler.unstable_flushAll() when the tasks scheduled in the test call Scheduler.log(...) — the do-while loop appends the values to yieldedValues and the post-flush check finds a non-null log.","commonSituations":"New tests modeled on React fixture tests where tasks log values; conditional logging that only fires for certain inputs; a leftover Scheduler.log() call inside a shared task helper copied from an older fixture.","solutions":["Replace the bare flush with expect(Scheduler).toFlushAndYield([...]) listing exactly the values the tasks log.","If the values are irrelevant, use unstable_flushAllWithoutAsserting() (optionally followed by unstable_clearLog()) instead of unstable_flushAll().","Use toFlushAndYieldThrough([...]) when only a prefix of the logged values is deterministic.","Delete stray Scheduler.log() calls left in shared helpers."],"exampleFix":"// before\nScheduler.scheduleCallback(NormalPriority, () => Scheduler.log('hi'));\nScheduler.unstable_flushAll(); // throws: something yielded a value\n\n// after\nScheduler.scheduleCallback(NormalPriority, () => Scheduler.log('hi'));\nexpect(Scheduler).toFlushAndYield(['hi']);","handlingStrategy":"validation","validationCode":"// If you do not intend to assert values, use the non-asserting variant up front.\nScheduler.unstable_flushAllWithoutAsserting(); // never throws on yielded values\nScheduler.unstable_clearLog(); // discard whatever was logged\n// otherwise declare expectations explicitly:\n// expect(Scheduler).toFlushAndYield(['a', 'b']);","typeGuard":null,"tryCatchPattern":"try {\n  Scheduler.unstable_flushAll();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('something yielded a value')) {\n    Scheduler.unstable_clearLog();\n    Scheduler.unstable_flushAllWithoutAsserting(); // re-flush without the strict check\n  } else {\n    throw e;\n  }\n}","preventionTips":["Whenever scheduled tasks call Scheduler.log(), assert with toFlushAndYield([...]) instead of unstable_flushAll().","Use toFlushAndYieldThrough for non-deterministic suffixes.","Remove stray log() calls from shared task helpers so strict flushes stay usable."],"tags":["scheduler","testing","mock","assertions"],"backgroundTag":"unasserted-yielded-log","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}