Skip to content

Commit 45ba73b

Browse files
committed
Wrap eventhandle-specific logic in a flag
1 parent c153679 commit 45ba73b

File tree

4 files changed

+74
-50
lines changed

4 files changed

+74
-50
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
2626
import type {HookFlags} from './ReactHookEffectTags';
2727

2828
import {
29+
enableCreateEventHandleAPI,
2930
enableProfilerTimer,
3031
enableProfilerCommitHooks,
3132
enableProfilerNestedUpdatePhase,
@@ -365,12 +366,16 @@ function commitBeforeMutationEffects_begin() {
365366
while (nextEffect !== null) {
366367
const fiber = nextEffect;
367368

368-
// TODO: Should wrap this in flags check, too, as optimization
369-
const deletions = fiber.deletions;
370-
if (deletions !== null) {
371-
for (let i = 0; i < deletions.length; i++) {
372-
const deletion = deletions[i];
373-
commitBeforeMutationEffectsDeletion(deletion);
369+
// This phase is only used for beforeActiveInstanceBlur.
370+
// Let's skip the whole loop if it's off.
371+
if (enableCreateEventHandleAPI) {
372+
// TODO: Should wrap this in flags check, too, as optimization
373+
const deletions = fiber.deletions;
374+
if (deletions !== null) {
375+
for (let i = 0; i < deletions.length; i++) {
376+
const deletion = deletions[i];
377+
commitBeforeMutationEffectsDeletion(deletion);
378+
}
374379
}
375380
}
376381

@@ -426,16 +431,18 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
426431
const current = finishedWork.alternate;
427432
const flags = finishedWork.flags;
428433

429-
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
430-
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
431-
// TODO: Move this out of the hot path using a dedicated effect tag.
432-
if (
433-
finishedWork.tag === SuspenseComponent &&
434-
isSuspenseBoundaryBeingHidden(current, finishedWork) &&
435-
doesFiberContain(finishedWork, focusedInstanceHandle)
436-
) {
437-
shouldFireAfterActiveInstanceBlur = true;
438-
beforeActiveInstanceBlur(finishedWork);
434+
if (enableCreateEventHandleAPI) {
435+
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
436+
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
437+
// TODO: Move this out of the hot path using a dedicated effect tag.
438+
if (
439+
finishedWork.tag === SuspenseComponent &&
440+
isSuspenseBoundaryBeingHidden(current, finishedWork) &&
441+
doesFiberContain(finishedWork, focusedInstanceHandle)
442+
) {
443+
shouldFireAfterActiveInstanceBlur = true;
444+
beforeActiveInstanceBlur(finishedWork);
445+
}
439446
}
440447
}
441448

@@ -531,13 +538,15 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
531538
}
532539

533540
function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
534-
// TODO (effects) It would be nice to avoid calling doesFiberContain()
535-
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
536-
// Use it to store which part of the tree the focused instance is in?
537-
// This assumes we can safely determine that instance during the "render" phase.
538-
if (doesFiberContain(deletion, ((focusedInstanceHandle: any): Fiber))) {
539-
shouldFireAfterActiveInstanceBlur = true;
540-
beforeActiveInstanceBlur(deletion);
541+
if (enableCreateEventHandleAPI) {
542+
// TODO (effects) It would be nice to avoid calling doesFiberContain()
543+
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
544+
// Use it to store which part of the tree the focused instance is in?
545+
// This assumes we can safely determine that instance during the "render" phase.
546+
if (doesFiberContain(deletion, ((focusedInstanceHandle: any): Fiber))) {
547+
shouldFireAfterActiveInstanceBlur = true;
548+
beforeActiveInstanceBlur(deletion);
549+
}
541550
}
542551
}
543552

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
2626
import type {HookFlags} from './ReactHookEffectTags';
2727

2828
import {
29+
enableCreateEventHandleAPI,
2930
enableProfilerTimer,
3031
enableProfilerCommitHooks,
3132
enableProfilerNestedUpdatePhase,
@@ -365,12 +366,16 @@ function commitBeforeMutationEffects_begin() {
365366
while (nextEffect !== null) {
366367
const fiber = nextEffect;
367368

368-
// TODO: Should wrap this in flags check, too, as optimization
369-
const deletions = fiber.deletions;
370-
if (deletions !== null) {
371-
for (let i = 0; i < deletions.length; i++) {
372-
const deletion = deletions[i];
373-
commitBeforeMutationEffectsDeletion(deletion);
369+
// This phase is only used for beforeActiveInstanceBlur.
370+
// Let's skip the whole loop if it's off.
371+
if (enableCreateEventHandleAPI) {
372+
// TODO: Should wrap this in flags check, too, as optimization
373+
const deletions = fiber.deletions;
374+
if (deletions !== null) {
375+
for (let i = 0; i < deletions.length; i++) {
376+
const deletion = deletions[i];
377+
commitBeforeMutationEffectsDeletion(deletion);
378+
}
374379
}
375380
}
376381

@@ -426,16 +431,18 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
426431
const current = finishedWork.alternate;
427432
const flags = finishedWork.flags;
428433

429-
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
430-
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
431-
// TODO: Move this out of the hot path using a dedicated effect tag.
432-
if (
433-
finishedWork.tag === SuspenseComponent &&
434-
isSuspenseBoundaryBeingHidden(current, finishedWork) &&
435-
doesFiberContain(finishedWork, focusedInstanceHandle)
436-
) {
437-
shouldFireAfterActiveInstanceBlur = true;
438-
beforeActiveInstanceBlur(finishedWork);
434+
if (enableCreateEventHandleAPI) {
435+
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
436+
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
437+
// TODO: Move this out of the hot path using a dedicated effect tag.
438+
if (
439+
finishedWork.tag === SuspenseComponent &&
440+
isSuspenseBoundaryBeingHidden(current, finishedWork) &&
441+
doesFiberContain(finishedWork, focusedInstanceHandle)
442+
) {
443+
shouldFireAfterActiveInstanceBlur = true;
444+
beforeActiveInstanceBlur(finishedWork);
445+
}
439446
}
440447
}
441448

@@ -531,13 +538,15 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
531538
}
532539

533540
function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
534-
// TODO (effects) It would be nice to avoid calling doesFiberContain()
535-
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
536-
// Use it to store which part of the tree the focused instance is in?
537-
// This assumes we can safely determine that instance during the "render" phase.
538-
if (doesFiberContain(deletion, ((focusedInstanceHandle: any): Fiber))) {
539-
shouldFireAfterActiveInstanceBlur = true;
540-
beforeActiveInstanceBlur(deletion);
541+
if (enableCreateEventHandleAPI) {
542+
// TODO (effects) It would be nice to avoid calling doesFiberContain()
543+
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
544+
// Use it to store which part of the tree the focused instance is in?
545+
// This assumes we can safely determine that instance during the "render" phase.
546+
if (doesFiberContain(deletion, ((focusedInstanceHandle: any): Fiber))) {
547+
shouldFireAfterActiveInstanceBlur = true;
548+
beforeActiveInstanceBlur(deletion);
549+
}
541550
}
542551
}
543552

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
warnAboutDeprecatedLifecycles,
2020
enableSuspenseServerRenderer,
2121
replayFailedUnitOfWorkWithInvokeGuardedCallback,
22+
enableCreateEventHandleAPI,
2223
enableProfilerTimer,
2324
enableProfilerCommitHooks,
2425
enableProfilerNestedUpdatePhase,
@@ -1854,8 +1855,10 @@ function commitRootImpl(root, renderPriorityLevel) {
18541855
// The next phase is the mutation phase, where we mutate the host tree.
18551856
commitMutationEffects(root, finishedWork, lanes);
18561857

1857-
if (shouldFireAfterActiveInstanceBlur) {
1858-
afterActiveInstanceBlur();
1858+
if (enableCreateEventHandleAPI) {
1859+
if (shouldFireAfterActiveInstanceBlur) {
1860+
afterActiveInstanceBlur();
1861+
}
18591862
}
18601863
resetAfterCommit(root.containerInfo);
18611864

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
warnAboutDeprecatedLifecycles,
2020
enableSuspenseServerRenderer,
2121
replayFailedUnitOfWorkWithInvokeGuardedCallback,
22+
enableCreateEventHandleAPI,
2223
enableProfilerTimer,
2324
enableProfilerCommitHooks,
2425
enableProfilerNestedUpdatePhase,
@@ -1854,8 +1855,10 @@ function commitRootImpl(root, renderPriorityLevel) {
18541855
// The next phase is the mutation phase, where we mutate the host tree.
18551856
commitMutationEffects(root, finishedWork, lanes);
18561857

1857-
if (shouldFireAfterActiveInstanceBlur) {
1858-
afterActiveInstanceBlur();
1858+
if (enableCreateEventHandleAPI) {
1859+
if (shouldFireAfterActiveInstanceBlur) {
1860+
afterActiveInstanceBlur();
1861+
}
18591862
}
18601863
resetAfterCommit(root.containerInfo);
18611864

0 commit comments

Comments
 (0)