Skip to content

Commit 61dd00d

Browse files
authored
Extract some of the tidy up changes from 19278 (#19315)
1 parent a2b4db0 commit 61dd00d

11 files changed

+184
-270
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import {
8585
enableDeprecatedFlareAPI,
8686
enableTrustedTypesIntegration,
8787
} from 'shared/ReactFeatureFlags';
88-
import {listenToReactPropEvent} from '../events/DOMModernPluginEventSystem';
88+
import {listenToReactEvent} from '../events/DOMModernPluginEventSystem';
8989
import {getEventListenerMap} from './ReactDOMComponentTree';
9090

9191
let didWarnInvalidHydration = false;
@@ -282,10 +282,7 @@ export function ensureListeningTo(
282282
'ensureListeningTo(): received a container that was not an element node. ' +
283283
'This is likely a bug in React.',
284284
);
285-
listenToReactPropEvent(
286-
reactPropEvent,
287-
((rootContainerElement: any): Element),
288-
);
285+
listenToReactEvent(reactPropEvent, ((rootContainerElement: any): Element));
289286
}
290287

291288
function getOwnerDocumentFromRootContainer(

packages/react-dom/src/client/ReactDOMEventHandle.js

+41-35
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import {
2424
} from './ReactDOMComponentTree';
2525
import {ELEMENT_NODE} from '../shared/HTMLNodeType';
2626
import {
27-
listenToTopLevelEvent,
27+
listenToNativeEvent,
2828
addEventTypeToDispatchConfig,
2929
} from '../events/DOMModernPluginEventSystem';
3030

3131
import {HostRoot, HostPortal} from 'react-reconciler/src/ReactWorkTags';
3232
import {
3333
PLUGIN_EVENT_SYSTEM,
34-
IS_TARGET_PHASE_ONLY,
34+
IS_EVENT_HANDLE_NON_MANAGED_NODE,
3535
} from '../events/EventSystemFlags';
3636

3737
import {
@@ -71,22 +71,22 @@ function isReactScope(target: EventTarget | ReactScopeInstance): boolean {
7171

7272
function createEventHandleListener(
7373
type: DOMTopLevelEventType,
74-
capture: boolean,
74+
isCapturePhaseListener: boolean,
7575
callback: (SyntheticEvent<EventTarget>) => void,
7676
): ReactDOMEventHandleListener {
7777
return {
7878
callback,
79-
capture,
79+
capture: isCapturePhaseListener,
8080
type,
8181
};
8282
}
8383

8484
function registerEventOnNearestTargetContainer(
8585
targetFiber: Fiber,
8686
topLevelType: DOMTopLevelEventType,
87-
passive: boolean | void,
88-
priority: EventPriority | void,
89-
capture: boolean,
87+
isPassiveListener: boolean | void,
88+
listenerPriority: EventPriority | void,
89+
isCapturePhaseListener: boolean,
9090
): void {
9191
// If it is, find the nearest root or portal and make it
9292
// our event handle target container.
@@ -99,23 +99,23 @@ function registerEventOnNearestTargetContainer(
9999
);
100100
}
101101
const listenerMap = getEventListenerMap(targetContainer);
102-
listenToTopLevelEvent(
102+
listenToNativeEvent(
103103
topLevelType,
104104
targetContainer,
105105
listenerMap,
106106
PLUGIN_EVENT_SYSTEM,
107-
capture,
108-
passive,
109-
priority,
107+
isCapturePhaseListener,
108+
isPassiveListener,
109+
listenerPriority,
110110
);
111111
}
112112

113113
function registerReactDOMEvent(
114114
target: EventTarget | ReactScopeInstance,
115115
topLevelType: DOMTopLevelEventType,
116-
passive: boolean | void,
117-
capture: boolean,
118-
priority: EventPriority | void,
116+
isPassiveListener: boolean | void,
117+
isCapturePhaseListener: boolean,
118+
listenerPriority: EventPriority | void,
119119
): void {
120120
// Check if the target is a DOM element.
121121
if ((target: any).nodeType === ELEMENT_NODE) {
@@ -132,9 +132,9 @@ function registerReactDOMEvent(
132132
registerEventOnNearestTargetContainer(
133133
targetFiber,
134134
topLevelType,
135-
passive,
136-
priority,
137-
capture,
135+
isPassiveListener,
136+
listenerPriority,
137+
isCapturePhaseListener,
138138
);
139139
} else if (enableScopeAPI && isReactScope(target)) {
140140
const scopeTarget = ((target: any): ReactScopeInstance);
@@ -146,21 +146,21 @@ function registerReactDOMEvent(
146146
registerEventOnNearestTargetContainer(
147147
targetFiber,
148148
topLevelType,
149-
passive,
150-
priority,
151-
capture,
149+
isPassiveListener,
150+
listenerPriority,
151+
isCapturePhaseListener,
152152
);
153153
} else if (isValidEventTarget(target)) {
154154
const eventTarget = ((target: any): EventTarget);
155155
const listenerMap = getEventListenerMap(eventTarget);
156-
listenToTopLevelEvent(
156+
listenToNativeEvent(
157157
topLevelType,
158158
eventTarget,
159159
listenerMap,
160-
PLUGIN_EVENT_SYSTEM | IS_TARGET_PHASE_ONLY,
161-
capture,
162-
passive,
163-
priority,
160+
PLUGIN_EVENT_SYSTEM | IS_EVENT_HANDLE_NON_MANAGED_NODE,
161+
isCapturePhaseListener,
162+
isPassiveListener,
163+
listenerPriority,
164164
);
165165
} else {
166166
invariant(
@@ -177,27 +177,27 @@ export function createEventHandle(
177177
): ReactDOMEventHandle {
178178
if (enableCreateEventHandleAPI) {
179179
const topLevelType = ((type: any): DOMTopLevelEventType);
180-
let capture = false;
181-
let passive = undefined; // Undefined means to use the browser default
182-
let priority;
180+
let isCapturePhaseListener = false;
181+
let isPassiveListener = undefined; // Undefined means to use the browser default
182+
let listenerPriority;
183183

184184
if (options != null) {
185185
const optionsCapture = options.capture;
186186
const optionsPassive = options.passive;
187187
const optionsPriority = options.priority;
188188

189189
if (typeof optionsCapture === 'boolean') {
190-
capture = optionsCapture;
190+
isCapturePhaseListener = optionsCapture;
191191
}
192192
if (typeof optionsPassive === 'boolean') {
193-
passive = optionsPassive;
193+
isPassiveListener = optionsPassive;
194194
}
195195
if (typeof optionsPriority === 'number') {
196-
priority = optionsPriority;
196+
listenerPriority = optionsPriority;
197197
}
198198
}
199-
if (priority === undefined) {
200-
priority = getEventPriorityForListenerSystem(topLevelType);
199+
if (listenerPriority === undefined) {
200+
listenerPriority = getEventPriorityForListenerSystem(topLevelType);
201201
}
202202

203203
const registeredReactDOMEvents = new PossiblyWeakSet();
@@ -213,13 +213,19 @@ export function createEventHandle(
213213
);
214214
if (!registeredReactDOMEvents.has(target)) {
215215
registeredReactDOMEvents.add(target);
216-
registerReactDOMEvent(target, topLevelType, passive, capture, priority);
216+
registerReactDOMEvent(
217+
target,
218+
topLevelType,
219+
isPassiveListener,
220+
isCapturePhaseListener,
221+
listenerPriority,
222+
);
217223
// Add the event to our known event types list.
218224
addEventTypeToDispatchConfig(topLevelType);
219225
}
220226
const listener = createEventHandleListener(
221227
topLevelType,
222-
capture,
228+
isCapturePhaseListener,
223229
callback,
224230
);
225231
let targetListeners = getEventHandlerListeners(target);

packages/react-dom/src/client/ReactDOMHostConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import {
8080
} from 'shared/ReactFeatureFlags';
8181
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
8282
import {TOP_BEFORE_BLUR, TOP_AFTER_BLUR} from '../events/DOMTopLevelEventTypes';
83-
import {listenToReactPropEvent} from '../events/DOMModernPluginEventSystem';
83+
import {listenToReactEvent} from '../events/DOMModernPluginEventSystem';
8484

8585
export type Type = string;
8686
export type Props = {
@@ -1111,7 +1111,7 @@ export function makeOpaqueHydratingObject(
11111111
}
11121112

11131113
export function preparePortalMount(portalInstance: Instance): void {
1114-
listenToReactPropEvent('onMouseEnter', portalInstance);
1114+
listenToReactEvent('onMouseEnter', portalInstance);
11151115
}
11161116

11171117
export function prepareScopeUpdate(

0 commit comments

Comments
 (0)