Skip to content

Wrap createEventHandle-specific logic in a flag #21657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';

import {
enableCreateEventHandleAPI,
enableProfilerTimer,
enableProfilerCommitHooks,
enableProfilerNestedUpdatePhase,
Expand Down Expand Up @@ -365,6 +366,9 @@ function commitBeforeMutationEffects_begin() {
while (nextEffect !== null) {
const fiber = nextEffect;

// This phase is only used for beforeActiveInstanceBlur.
// Let's skip the whole loop if it's off.
if (enableCreateEventHandleAPI) {
// TODO: Should wrap this in flags check, too, as optimization
const deletions = fiber.deletions;
if (deletions !== null) {
Expand All @@ -373,6 +377,7 @@ function commitBeforeMutationEffects_begin() {
commitBeforeMutationEffectsDeletion(deletion);
}
}
}

const child = fiber.child;
if (
Expand Down Expand Up @@ -426,6 +431,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
const current = finishedWork.alternate;
const flags = finishedWork.flags;

if (enableCreateEventHandleAPI) {
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
// TODO: Move this out of the hot path using a dedicated effect tag.
Expand All @@ -438,6 +444,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
beforeActiveInstanceBlur(finishedWork);
}
}
}

if ((flags & Snapshot) !== NoFlags) {
setCurrentDebugFiberInDEV(finishedWork);
Expand Down Expand Up @@ -531,6 +538,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
}

function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
if (enableCreateEventHandleAPI) {
// TODO (effects) It would be nice to avoid calling doesFiberContain()
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
// Use it to store which part of the tree the focused instance is in?
Expand All @@ -540,6 +548,7 @@ function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
beforeActiveInstanceBlur(deletion);
}
}
}

function commitHookEffectListUnmount(
flags: HookFlags,
Expand Down
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';

import {
enableCreateEventHandleAPI,
enableProfilerTimer,
enableProfilerCommitHooks,
enableProfilerNestedUpdatePhase,
Expand Down Expand Up @@ -365,6 +366,9 @@ function commitBeforeMutationEffects_begin() {
while (nextEffect !== null) {
const fiber = nextEffect;

// This phase is only used for beforeActiveInstanceBlur.
// Let's skip the whole loop if it's off.
if (enableCreateEventHandleAPI) {
// TODO: Should wrap this in flags check, too, as optimization
const deletions = fiber.deletions;
if (deletions !== null) {
Expand All @@ -373,6 +377,7 @@ function commitBeforeMutationEffects_begin() {
commitBeforeMutationEffectsDeletion(deletion);
}
}
}

const child = fiber.child;
if (
Expand Down Expand Up @@ -426,6 +431,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
const current = finishedWork.alternate;
const flags = finishedWork.flags;

if (enableCreateEventHandleAPI) {
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
// TODO: Move this out of the hot path using a dedicated effect tag.
Expand All @@ -438,6 +444,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
beforeActiveInstanceBlur(finishedWork);
}
}
}

if ((flags & Snapshot) !== NoFlags) {
setCurrentDebugFiberInDEV(finishedWork);
Expand Down Expand Up @@ -531,6 +538,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
}

function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
if (enableCreateEventHandleAPI) {
// TODO (effects) It would be nice to avoid calling doesFiberContain()
// Maybe we can repurpose one of the subtreeFlags positions for this instead?
// Use it to store which part of the tree the focused instance is in?
Expand All @@ -540,6 +548,7 @@ function commitBeforeMutationEffectsDeletion(deletion: Fiber) {
beforeActiveInstanceBlur(deletion);
}
}
}

function commitHookEffectListUnmount(
flags: HookFlags,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
warnAboutDeprecatedLifecycles,
enableSuspenseServerRenderer,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
enableCreateEventHandleAPI,
enableProfilerTimer,
enableProfilerCommitHooks,
enableProfilerNestedUpdatePhase,
Expand Down Expand Up @@ -1854,9 +1855,11 @@ function commitRootImpl(root, renderPriorityLevel) {
// The next phase is the mutation phase, where we mutate the host tree.
commitMutationEffects(root, finishedWork, lanes);

if (enableCreateEventHandleAPI) {
if (shouldFireAfterActiveInstanceBlur) {
afterActiveInstanceBlur();
}
}
resetAfterCommit(root.containerInfo);

// The work-in-progress tree is now the current tree. This must come after
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
warnAboutDeprecatedLifecycles,
enableSuspenseServerRenderer,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
enableCreateEventHandleAPI,
enableProfilerTimer,
enableProfilerCommitHooks,
enableProfilerNestedUpdatePhase,
Expand Down Expand Up @@ -1854,9 +1855,11 @@ function commitRootImpl(root, renderPriorityLevel) {
// The next phase is the mutation phase, where we mutate the host tree.
commitMutationEffects(root, finishedWork, lanes);

if (enableCreateEventHandleAPI) {
if (shouldFireAfterActiveInstanceBlur) {
afterActiveInstanceBlur();
}
}
resetAfterCommit(root.containerInfo);

// The work-in-progress tree is now the current tree. This must come after
Expand Down