From 88e0849856bb4a43639373919b9066cf0045697b Mon Sep 17 00:00:00 2001 From: Prashant Yadav Date: Sun, 3 May 2026 14:10:31 +0530 Subject: [PATCH] Fix: avoid re-entrant work during render or commit --- .../react-reconciler/src/ReactFiberRootScheduler.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberRootScheduler.js b/packages/react-reconciler/src/ReactFiberRootScheduler.js index 26b625522762..0c0c9aae91ea 100644 --- a/packages/react-reconciler/src/ReactFiberRootScheduler.js +++ b/packages/react-reconciler/src/ReactFiberRootScheduler.js @@ -193,6 +193,11 @@ function flushSyncWorkAcrossRoots_impl( return; } + const executionContext = getExecutionContext(); + if ((executionContext & (RenderContext | CommitContext)) !== NoContext) { + return; + } + if (!mightHavePendingSyncWork) { // Fast path. There's no sync work to do. return; @@ -527,9 +532,10 @@ function performWorkOnRootViaSchedulerTask( trackSchedulerEvent(); } - if (hasPendingCommitEffects()) { - // We are currently in the middle of an async committing (such as a View Transition). - // We could force these to flush eagerly but it's better to defer any work until + const executionContext = getExecutionContext(); + if ((executionContext & (RenderContext | CommitContext)) !== NoContext) { + // We are currently in the middle of a render or commit. We could force + // these to flush eagerly but it's better to defer any work until // it finishes. This may not be the same root as we're waiting on. // TODO: This relies on the commit eventually calling ensureRootIsScheduled which // always calls processRootScheduleInMicrotask which in turn always loops through