Skip to content

Commit 9f40f16

Browse files
authored
Remove the native EventTarget event-dispatch flag (#59896)
Summary: Remove `enableNativeEventTargetEventDispatching` and retain its enabled paths unconditionally. Preserve the separate `enableImperativeEvents` gate and existing test behavior. Test edits remove retired flag configuration and correct the typing required by the ungated `EventTarget` inheritance; no assertions or helper functions were added. Regenerate the public API snapshot for the permanent `EventTarget` inheritance. Changelog: [Internal] Reviewed By: zeyap Differential Revision: D130671804 Pull Request resolved: #59896
1 parent 975584c commit 9f40f16

15 files changed

Lines changed: 347 additions & 352 deletions

‎packages/react-native/ReactNativeApi.d.ts‎

Lines changed: 204 additions & 128 deletions
Large diffs are not rendered by default.

‎packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,6 @@ const definitions: FeatureFlagDefinitions = {
11601160
},
11611161
ossReleaseStage: 'none',
11621162
},
1163-
enableNativeEventTargetEventDispatching: {
1164-
defaultValue: true,
1165-
metadata: {
1166-
dateAdded: '2026-04-13',
1167-
description:
1168-
'When enabled, the React Native renderer dispatches events through the W3C EventTarget API (addEventListener/dispatchEvent) instead of the legacy plugin-based system.',
1169-
expectedReleaseValue: true,
1170-
purpose: 'experimentation',
1171-
},
1172-
ossReleaseStage: 'none',
1173-
},
11741163
externalElementInspectionEnabled: {
11751164
defaultValue: true,
11761165
metadata: {

‎packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<248a6701e98d6850499d84dd5c2bff5f>>
7+
* @generated SignedSource<<715bdce4ff85be24d125b1c894da41d8>>
88
* @flow strict
99
* @noformat
1010
*/
@@ -34,7 +34,6 @@ export type ReactNativeFeatureFlagsJsOnly = Readonly<{
3434
animatedKeepListenersOnDetach: Getter<boolean>,
3535
animatedShouldSyncValueBeforeStartCallback: Getter<boolean>,
3636
deferFlatListFocusChangeRenderUpdate: Getter<boolean>,
37-
enableNativeEventTargetEventDispatching: Getter<boolean>,
3837
externalElementInspectionEnabled: Getter<boolean>,
3938
fixCrossOrientationNestedListViewability: Getter<boolean>,
4039
fixVirtualizeListCollapseWindowSize: Getter<boolean>,
@@ -179,11 +178,6 @@ export const animatedShouldSyncValueBeforeStartCallback: Getter<boolean> = creat
179178
*/
180179
export const deferFlatListFocusChangeRenderUpdate: Getter<boolean> = createJavaScriptFlagGetter('deferFlatListFocusChangeRenderUpdate', false);
181180

182-
/**
183-
* When enabled, the React Native renderer dispatches events through the W3C EventTarget API (addEventListener/dispatchEvent) instead of the legacy plugin-based system.
184-
*/
185-
export const enableNativeEventTargetEventDispatching: Getter<boolean> = createJavaScriptFlagGetter('enableNativeEventTargetEventDispatching', true);
186-
187181
/**
188182
* Enable the external inspection API for DevTools to communicate with the Inspector overlay.
189183
*/

‎packages/react-native/src/private/renderer/core/__tests__/EventDispatching-benchmark-itest.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @fantom_flags enableNativeEventTargetEventDispatching:*
87
* @flow strict-local
98
* @format
109
*/

‎packages/react-native/src/private/renderer/core/__tests__/EventTargetDispatching-itest.js‎

Lines changed: 55 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @fantom_flags enableNativeEventTargetEventDispatching:*
87
* @fantom_flags enableImperativeEvents:*
98
* @flow strict-local
109
* @format
@@ -480,13 +479,10 @@ describe('EventTarget-based Event Dispatching', () => {
480479
});
481480

482481
// --- addEventListener / removeEventListener on refs ---
483-
// These tests require both `enableNativeEventTargetEventDispatching` and
484-
// `enableImperativeEvents` to be enabled, since the public `addEventListener`
485-
// API on element refs is only available when both flags are on. They are
486-
// skipped for the other flag combinations.
482+
// These tests require `enableImperativeEvents` to be enabled, since the
483+
// public `addEventListener` API on element refs is only available then.
487484

488-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching() &&
489-
ReactNativeFeatureFlags.enableImperativeEvents()
485+
(ReactNativeFeatureFlags.enableImperativeEvents() === true
490486
? describe
491487
: describe.skip)('addEventListener / removeEventListener', () => {
492488
it('addEventListener on a ref receives dispatched events', () => {
@@ -869,74 +865,66 @@ describe('EventTarget-based Event Dispatching', () => {
869865
}
870866
});
871867

872-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching()
873-
? it
874-
: it.skip)(
875-
'event.target points to the original target and event.currentTarget changes at each step',
876-
() => {
877-
const root = Fantom.createRoot();
878-
const parentRef = React.createRef<React.ElementRef<typeof View>>();
879-
const childRef = React.createRef<React.ElementRef<typeof View>>();
880-
const targets: Array<{target: unknown, currentTarget: unknown}> = [];
868+
it('event.target points to the original target and event.currentTarget changes at each step', () => {
869+
const root = Fantom.createRoot();
870+
const parentRef = React.createRef<React.ElementRef<typeof View>>();
871+
const childRef = React.createRef<React.ElementRef<typeof View>>();
872+
const targets: Array<{target: unknown, currentTarget: unknown}> = [];
881873

882-
Fantom.runTask(() => {
883-
root.render(
874+
Fantom.runTask(() => {
875+
root.render(
876+
<View
877+
ref={parentRef}
878+
onPointerUpCapture={(e: $FlowFixMe) => {
879+
targets.push({
880+
target: e.target,
881+
currentTarget: e.currentTarget,
882+
});
883+
}}
884+
onPointerUp={(e: $FlowFixMe) => {
885+
targets.push({
886+
target: e.target,
887+
currentTarget: e.currentTarget,
888+
});
889+
}}>
884890
<View
885-
ref={parentRef}
886-
onPointerUpCapture={(e: $FlowFixMe) => {
887-
targets.push({
888-
target: e.target,
889-
currentTarget: e.currentTarget,
890-
});
891-
}}
891+
ref={childRef}
892892
onPointerUp={(e: $FlowFixMe) => {
893893
targets.push({
894894
target: e.target,
895895
currentTarget: e.currentTarget,
896896
});
897-
}}>
898-
<View
899-
ref={childRef}
900-
onPointerUp={(e: $FlowFixMe) => {
901-
targets.push({
902-
target: e.target,
903-
currentTarget: e.currentTarget,
904-
});
905-
}}
906-
/>
907-
</View>,
908-
);
909-
});
910-
911-
Fantom.dispatchNativeEvent(
912-
childRef,
913-
'onPointerUp',
914-
{x: 0, y: 0},
915-
{
916-
category: Fantom.NativeEventCategory.Discrete,
917-
},
897+
}}
898+
/>
899+
</View>,
918900
);
901+
});
919902

920-
expect(targets).toHaveLength(3);
903+
Fantom.dispatchNativeEvent(
904+
childRef,
905+
'onPointerUp',
906+
{x: 0, y: 0},
907+
{
908+
category: Fantom.NativeEventCategory.Discrete,
909+
},
910+
);
921911

922-
// event.target is always the original target element
923-
expect(targets[0].target).toBe(childRef.current);
924-
expect(targets[1].target).toBe(childRef.current);
925-
expect(targets[2].target).toBe(childRef.current);
912+
expect(targets).toHaveLength(3);
926913

927-
// event.currentTarget changes at each propagation step
928-
// Capture: parent
929-
expect(targets[0].currentTarget).toBe(parentRef.current);
930-
// Bubble: child, then parent
931-
expect(targets[1].currentTarget).toBe(childRef.current);
932-
expect(targets[2].currentTarget).toBe(parentRef.current);
933-
},
934-
);
914+
// event.target is always the original target element
915+
expect(targets[0].target).toBe(childRef.current);
916+
expect(targets[1].target).toBe(childRef.current);
917+
expect(targets[2].target).toBe(childRef.current);
935918

936-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching() &&
937-
ReactNativeFeatureFlags.enableImperativeEvents()
938-
? it
939-
: it.skip)(
919+
// event.currentTarget changes at each propagation step
920+
// Capture: parent
921+
expect(targets[0].currentTarget).toBe(parentRef.current);
922+
// Bubble: child, then parent
923+
expect(targets[1].currentTarget).toBe(childRef.current);
924+
expect(targets[2].currentTarget).toBe(parentRef.current);
925+
});
926+
927+
(ReactNativeFeatureFlags.enableImperativeEvents() === true ? it : it.skip)(
940928
'direct (non-bubbling) events do not propagate via addEventListener',
941929
() => {
942930
const root = Fantom.createRoot();
@@ -983,8 +971,7 @@ describe('EventTarget-based Event Dispatching', () => {
983971
},
984972
);
985973

986-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching() &&
987-
ReactNativeFeatureFlags.enableImperativeEvents()
974+
(ReactNativeFeatureFlags.enableImperativeEvents() === true
988975
? describe
989976
: describe.skip)('bubbling to document element and document', () => {
990977
it('event bubbles from child up to the document element', () => {
@@ -1374,9 +1361,7 @@ describe('EventTarget-based Event Dispatching', () => {
13741361
});
13751362
});
13761363

1377-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching()
1378-
? describe
1379-
: describe.skip)('event timestamps', () => {
1364+
describe('event timestamps', () => {
13801365
it('event preserves native timestamp from nativeEvent.timeStamp', () => {
13811366
const root = Fantom.createRoot();
13821367
const ref = React.createRef<React.ElementRef<typeof View>>();
@@ -1661,11 +1646,8 @@ describe('EventTarget-based Event Dispatching', () => {
16611646
});
16621647

16631648
// The dispatch-behavior tests use `addEventListener` on refs and the
1664-
// document element, which is only available when both
1665-
// `enableNativeEventTargetEventDispatching` and `enableImperativeEvents`
1666-
// are enabled.
1667-
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching() &&
1668-
ReactNativeFeatureFlags.enableImperativeEvents()
1649+
// document element, which requires `enableImperativeEvents` to be enabled.
1650+
(ReactNativeFeatureFlags.enableImperativeEvents() === true
16691651
? describe
16701652
: describe.skip)('direct events (rnIsDirect) — dispatch behavior', () => {
16711653
it('dispatches onLayout to the target but never to ancestor onLayout props or bubble listeners', () => {

‎packages/react-native/src/private/renderer/core/__tests__/ResponderEventTarget-itest.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @fantom_flags enableNativeEventTargetEventDispatching:*
87
* @flow strict-local
98
* @format
109
*/

‎packages/react-native/src/private/renderer/events/dispatchNativeEvent.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import {
3333
* 1. Responder negotiation (touch handling, grant/release lifecycle)
3434
* 2. Normal event dispatch via dispatchTrustedEvent (capture/bubble phases)
3535
*
36-
* Called from the React renderer's dispatchEvent when
37-
* enableNativeEventTargetEventDispatching is enabled.
36+
* Called from the React renderer's dispatchEvent.
3837
*/
3938
export default function dispatchNativeEvent(
4039
target: ?EventTarget,

‎packages/react-native/src/private/webapis/dom/events/EventTarget.js‎

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See https://dom.spec.whatwg.org/#interface-eventtarget.
1414
*/
1515

16+
import type {AbortSignal as InternalAbortSignal} from '../abort-api/AbortSignal';
1617
import type {EventPhase} from './Event';
1718

18-
import * as ReactNativeFeatureFlags from '../../../featureflags/ReactNativeFeatureFlags';
1919
import {setPlatformObject} from '../../webidl/PlatformObjects';
2020
import Event from './Event';
2121
import {
@@ -51,7 +51,7 @@ export type AddEventListenerOptions = Readonly<{
5151
...EventListenerOptions,
5252
passive?: boolean,
5353
once?: boolean,
54-
signal?: AbortSignal,
54+
signal?: InternalAbortSignal,
5555
}>;
5656

5757
type EventListenerRegistration = {
@@ -403,66 +403,49 @@ function invoke(
403403

404404
setCurrentTarget(event, eventTarget);
405405

406-
if (ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching()) {
407-
// Resolve the prop-based listener. Pass the event so subclasses can read
408-
// its `type` and any pre-resolved internal slots; pass `isCapture`
409-
// separately because it can't be derived from `event.eventPhase` (which
410-
// is `AT_TARGET` during both passes through the target node).
411-
// $FlowExpectedError[prop-missing]
412-
const propListener: EventCallback | null = eventTarget[
413-
EVENT_TARGET_GET_DECLARATIVE_LISTENER_KEY
414-
](event, isCapture);
415-
416-
const listenersByType = getListenersForPhase(eventTarget, isCapture);
417-
const maybeListeners = listenersByType?.get(event.type);
418-
419-
// Fast path: only a prop listener (no `addEventListener` listeners).
420-
// This is the overwhelmingly common case for React-driven dispatch.
421-
if (maybeListeners == null) {
422-
if (propListener == null) {
423-
return;
424-
}
425-
const currentEvent = global.event;
426-
global.event = event;
427-
try {
428-
propListener.call(eventTarget, event);
429-
} catch (error) {
430-
handleListenerError(error, errorState);
431-
}
432-
global.event = currentEvent;
433-
return;
434-
}
406+
// Resolve the prop-based listener. Pass the event so subclasses can read
407+
// its `type` and any pre-resolved internal slots; pass `isCapture`
408+
// separately because it can't be derived from `event.eventPhase` (which
409+
// is `AT_TARGET` during both passes through the target node).
410+
// $FlowExpectedError[prop-missing]
411+
const propListener: EventCallback | null = eventTarget[
412+
EVENT_TARGET_GET_DECLARATIVE_LISTENER_KEY
413+
](event, isCapture);
435414

436-
// Slow path: combine prop listener + addEventListener listeners.
437-
const listeners: Array<EventListenerRegistration> = [];
438-
if (propListener != null) {
439-
listeners.push({
440-
callback: propListener,
441-
passive: false,
442-
once: false,
443-
removed: false,
444-
});
415+
const listenersByType = getListenersForPhase(eventTarget, isCapture);
416+
const maybeListeners = listenersByType?.get(event.type);
417+
418+
// Fast path: only a prop listener (no `addEventListener` listeners).
419+
// This is the overwhelmingly common case for React-driven dispatch.
420+
if (maybeListeners == null) {
421+
if (propListener == null) {
422+
return;
445423
}
446-
for (const registration of maybeListeners.values()) {
447-
listeners.push(registration);
424+
const currentEvent = global.event;
425+
global.event = event;
426+
try {
427+
propListener.call(eventTarget, event);
428+
} catch (error) {
429+
handleListenerError(error, errorState);
448430
}
449-
invokeListeners(eventTarget, event, listeners, isCapture, errorState);
431+
global.event = currentEvent;
450432
return;
451433
}
452434

453-
// Legacy path (flag OFF): only `addEventListener` listeners.
454-
const listenersByType = getListenersForPhase(eventTarget, isCapture);
455-
const maybeListeners = listenersByType?.get(event.type);
456-
if (maybeListeners == null) {
457-
return;
435+
// Slow path: combine prop listener + addEventListener listeners.
436+
const listeners: Array<EventListenerRegistration> = [];
437+
if (propListener != null) {
438+
listeners.push({
439+
callback: propListener,
440+
passive: false,
441+
once: false,
442+
removed: false,
443+
});
444+
}
445+
for (const registration of maybeListeners.values()) {
446+
listeners.push(registration);
458447
}
459-
invokeListeners(
460-
eventTarget,
461-
event,
462-
Array.from(maybeListeners.values()),
463-
isCapture,
464-
errorState,
465-
);
448+
invokeListeners(eventTarget, event, listeners, isCapture, errorState);
466449
}
467450

468451
function invokeListeners(

‎packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-benchmark-itest.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @fantom_flags enableNativeEventTargetEventDispatching:*
87
* @flow strict-local
98
* @format
109
*/

0 commit comments

Comments
 (0)