{"record":{"id":"a745e3866eeb7fd4","repo":"facebook/react","slug":"331","errorCode":"331","errorMessage":"Cannot flush passive effects while already rendering.","messagePattern":"Cannot flush passive effects while already rendering\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactFiberWorkLoop.js","lineNumber":4750,"sourceCode":"\n  const root = pendingEffectsRoot;\n  const lanes = pendingEffectsLanes;\n  pendingEffectsStatus = NO_PENDING_EFFECTS;\n  pendingEffectsRoot = null as any; // Clear for GC purposes.\n  pendingFinishedWork = null as any; // Clear for GC purposes.\n  // TODO: This is sometimes out of sync with pendingEffectsRoot.\n  // Figure out why and fix it. It's not causing any known issues (probably\n  // because it's only used for profiling), but it's a refactor hazard.\n  pendingEffectsLanes = NoLanes;\n\n  if (enableYieldingBeforePassive) {\n    // We've finished our work for this render pass.\n    root.callbackNode = null;\n    root.callbackPriority = NoLane;\n  }\n\n  if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {\n    throw new Error('Cannot flush passive effects while already rendering.');\n  }\n\n  if (enableProfilerTimer && enableComponentPerformanceTrack) {\n    // We're about to log a lot of profiling for this commit.\n    // We set this once so we don't have to recompute it for every log.\n    setCurrentTrackFromLanes(lanes);\n  }\n\n  if (__DEV__) {\n    isFlushingPassiveEffects = true;\n    didScheduleUpdateDuringPassiveEffects = false;\n  }\n\n  let passiveEffectStartTime = 0;\n  if (enableProfilerTimer && enableComponentPerformanceTrack) {\n    resetCommitErrors();\n    passiveEffectStartTime = now();\n    if (pendingDelayedCommitReason === ANIMATION_STARTED_COMMIT) {","sourceCodeStart":4732,"sourceCodeEnd":4768,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberWorkLoop.js#L4732-L4768","documentation":"flushPassiveEffects must run outside render and commit: it can itself perform work and re-enter the scheduler. The guard asserts executionContext has neither RenderContext nor CommitContext when passive effects flush (error code 331); a violation means passive effects were flushed synchronously from inside a render or commit phase — a reconciler re-entrancy invariant.","triggerScenarios":"A passive-effect flush being scheduled and executed synchronously while the reconciler is inside render or commit context, e.g. via an interleaved sync update or misuse of flushSync-style APIs from commit-phase code.","commonSituations":"flushSync or legacy sync lifecycle paths triggering effect flushes during commit; two react-dom copies sharing one root; upstream regressions in effect scheduling (mostly fixed in current releases).","solutions":["Upgrade react and react-dom in lockstep to the latest version","Dedupe react/react-dom in the bundle (npm ls react react-dom)","Avoid calling flushSync from effects, layout effects, or commit-phase hooks","File a React issue with the stack trace if it persists on the latest stable release"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not trigger effect flushes synchronously from render or commit code","Avoid flushSync inside passive effects","Keep matched react/react-dom versions to share one scheduling implementation"],"tags":["internal-invariant","passive-effects","reentrancy"],"backgroundTag":"react-internal-invariant","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}