From d8b903f49edebdd9ed081ff0514c28fe130cd510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Thu, 2 Jan 2025 14:34:26 -0500 Subject: [PATCH] [Fiber] Avoid return value from commitBeforeMutationEffects (#31922) This is behind an unusual flag (enableCreateEventHandleAPI) that doesn't serve a special return value. I'll be collecting other flags from this phase too. We can just use the global flag and reset it before the next mutation phase. Unlike focusedInstanceHandle this doesn't leak any memory in the meantime. --- packages/react-reconciler/src/ReactFiberCommitWork.js | 9 +++------ packages/react-reconciler/src/ReactFiberWorkLoop.js | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index a244c65e3e..80a27c4502 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -236,23 +236,20 @@ let inProgressLanes: Lanes | null = null; let inProgressRoot: FiberRoot | null = null; let focusedInstanceHandle: null | Fiber = null; -let shouldFireAfterActiveInstanceBlur: boolean = false; +export let shouldFireAfterActiveInstanceBlur: boolean = false; export function commitBeforeMutationEffects( root: FiberRoot, firstChild: Fiber, -): boolean { +): void { focusedInstanceHandle = prepareForCommit(root.containerInfo); + shouldFireAfterActiveInstanceBlur = false; nextEffect = firstChild; commitBeforeMutationEffects_begin(); // We no longer need to track the active instance fiber - const shouldFire = shouldFireAfterActiveInstanceBlur; - shouldFireAfterActiveInstanceBlur = false; focusedInstanceHandle = null; - - return shouldFire; } function commitBeforeMutationEffects_begin() { diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index ded26ed6e2..26544788f1 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -198,6 +198,7 @@ import { } from './ReactFiberThrow'; import { commitBeforeMutationEffects, + shouldFireAfterActiveInstanceBlur, commitLayoutEffects, commitMutationEffects, commitPassiveMountEffects, @@ -3384,10 +3385,7 @@ function commitRootImpl( // The first phase a "before mutation" phase. We use this phase to read the // state of the host tree right before we mutate it. This is where // getSnapshotBeforeUpdate is called. - const shouldFireAfterActiveInstanceBlur = commitBeforeMutationEffects( - root, - finishedWork, - ); + commitBeforeMutationEffects(root, finishedWork); // The next phase is the mutation phase, where we mutate the host tree. commitMutationEffects(root, finishedWork, lanes);