[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.
Sebastian Markbåge committed
Jan 2, 2025 at 14:34 UTC
d8b903f49edebdd9ed081ff0514c28fe130cd510
2 files changed
+5
-10
packages/react-reconciler/src/ReactFiberCommitWork.js
+3
-6
@@ -236,23 +236,20 @@ let inProgressLanes: Lanes | null = null;
236
let inProgressRoot: FiberRoot | null = null;
237
238
let focusedInstanceHandle: null | Fiber = null;
239
-let shouldFireAfterActiveInstanceBlur: boolean = false;
239
+export let shouldFireAfterActiveInstanceBlur: boolean = false;
240
241
export function commitBeforeMutationEffects(
242
root: FiberRoot,
243
firstChild: Fiber,
244
-): boolean {
244
+): void {
245
focusedInstanceHandle = prepareForCommit(root.containerInfo);
246
+ shouldFireAfterActiveInstanceBlur = false;
247
248
nextEffect = firstChild;
249
commitBeforeMutationEffects_begin();
250
251
// We no longer need to track the active instance fiber
251
- const shouldFire = shouldFireAfterActiveInstanceBlur;
252
- shouldFireAfterActiveInstanceBlur = false;
252
focusedInstanceHandle = null;
254
-
255
- return shouldFire;
253
}
254
255
function commitBeforeMutationEffects_begin() {
packages/react-reconciler/src/ReactFiberWorkLoop.js
+2
-4
@@ -198,6 +198,7 @@ import {
198
} from './ReactFiberThrow';
199
import {
200
commitBeforeMutationEffects,
201
+ shouldFireAfterActiveInstanceBlur,
202
commitLayoutEffects,
203
commitMutationEffects,
204
commitPassiveMountEffects,
@@ -3384,10 +3385,7 @@ function commitRootImpl(
3385
// The first phase a "before mutation" phase. We use this phase to read the
3386
// state of the host tree right before we mutate it. This is where
3387
// getSnapshotBeforeUpdate is called.
3387
- const shouldFireAfterActiveInstanceBlur = commitBeforeMutationEffects(
3388
- root,
3389
- finishedWork,
3390
- );
3388
+ commitBeforeMutationEffects(root, finishedWork);
3389
3390
// The next phase is the mutation phase, where we mutate the host tree.
3391
commitMutationEffects(root, finishedWork, lanes);