[internal] add feature flag to fix event handle API in Activity #35562
+999
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Noticed this TODO was never implemented, so this implements support for Activity inside the deprecated, never shipping
enableCreateEventHandleAPIfeature used internally until we remove the flag.Also adds a bunch of test for this API with Activity and LegacyHidden, with inline gates for the differences with the flags.
Below is the claude summary.
Details
Fix Event Handle API blur events for Activity
Problem
The
beforeblurandafterblurevents from thecreateEventHandleAPI were not firing when a focused element was hidden using<React.Activity>. This was because the blur check incommitBeforeMutationEffectsOnFiberonly handledSuspenseComponent, notOffscreenComponent(which Activity uses internally).Solution
Added a check for
OffscreenComponentvisibility transitions behind a new feature flagenableEventAPIActivityFix.Files Modified
1.
packages/react-reconciler/src/ReactFiberCommitWork.jsAdded blur event handling for Activity (OffscreenComponent):
2. Feature Flag Files
Added
enableEventAPIActivityFixto all feature flag files:ReactFeatureFlags.jsfalse(default)ReactFeatureFlags.www-dynamic.js__VARIANT__(dynamic)ReactFeatureFlags.www.jsReactFeatureFlags.test-renderer.jsfalseReactFeatureFlags.test-renderer.www.jsfalseReactFeatureFlags.test-renderer.native-fb.jsfalse3.
packages/react-dom/src/events/__tests__/DOMPluginEventSystem-test.internal.jsAdded 22 new tests (from 120 → 142 total):
Activity tests (6 tests)
beforeblur and afterblur are called after a focused element is hiddenbeforeblur and afterblur are called after a nested focused element is hiddenbeforeblur should skip handlers from a hidden subtree after the focused element is hidden via ActivityLegacyHidden tests (6 tests)
beforeblur and afterblur are not called after a focused element is hidden inside LegacyHiddenbeforeblur and afterblur are not called after a nested focused element is hidden inside LegacyHiddenbeforeblur is not called after the focused element is hidden inside LegacyHiddenNested Activity + LegacyHidden tests (10 tests)
<Activity><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><Activity><LegacyHidden><Activity>Key Design Decisions
Activity triggers blur, LegacyHidden does not - LegacyHidden behavior remains unchanged for backwards compatibility
Inline gate pattern - Tests use
if(gate('enableEventAPIActivityFix'))to test both flag states in a single testWorks with enableViewTransition - The fix correctly handles the ViewTransition early exit path
Test Results
variant=true(enableEventAPIActivityFix ON)variant=false(enableEventAPIActivityFix OFF)enableViewTransition=true