8
8
*/
9
9
10
10
import type { DOMEventName } from '../events/DOMEventNames' ;
11
- import type { EventPriority , ReactScopeInstance } from 'shared/ReactTypes' ;
11
+ import type { ReactScopeInstance } from 'shared/ReactTypes' ;
12
12
import type {
13
13
ReactDOMEventHandle ,
14
14
ReactDOMEventHandleListener ,
15
15
} from '../shared/ReactDOMTypes' ;
16
16
17
- import { getEventPriorityForListenerSystem } from '../events/DOMEventProperties' ;
18
17
import { allNativeEvents } from '../events/EventRegistry' ;
19
18
import {
20
19
getClosestInstanceFromNode ,
@@ -25,10 +24,7 @@ import {
25
24
addEventHandleToTarget ,
26
25
} from './ReactDOMComponentTree' ;
27
26
import { ELEMENT_NODE , COMMENT_NODE } from '../shared/HTMLNodeType' ;
28
- import {
29
- listenToNativeEvent ,
30
- addEventTypeToDispatchConfig ,
31
- } from '../events/DOMPluginEventSystem' ;
27
+ import { listenToNativeEvent } from '../events/DOMPluginEventSystem' ;
32
28
33
29
import { HostRoot , HostPortal } from 'react-reconciler/src/ReactWorkTags' ;
34
30
import { IS_EVENT_HANDLE_NON_MANAGED_NODE } from '../events/EventSystemFlags' ;
@@ -42,8 +38,6 @@ import invariant from 'shared/invariant';
42
38
43
39
type EventHandleOptions = { |
44
40
capture ? : boolean ,
45
- passive ? : boolean ,
46
- priority ? : EventPriority ,
47
41
| } ;
48
42
49
43
function getNearestRootOrPortalContainer ( node : Fiber ) : null | Element {
@@ -82,76 +76,76 @@ function createEventHandleListener(
82
76
function registerEventOnNearestTargetContainer (
83
77
targetFiber : Fiber ,
84
78
domEventName : DOMEventName ,
85
- isPassiveListener : boolean | void ,
86
- listenerPriority : EventPriority | void ,
87
79
isCapturePhaseListener : boolean ,
88
80
targetElement : Element | null ,
89
81
) : void {
90
- // If it is, find the nearest root or portal and make it
91
- // our event handle target container.
92
- let targetContainer = getNearestRootOrPortalContainer ( targetFiber ) ;
93
- if ( targetContainer === null ) {
94
- invariant (
95
- false ,
96
- 'ReactDOM.createEventHandle: setListener called on an target ' +
97
- 'that did not have a corresponding root. This is likely a bug in React.' ,
82
+ if ( ! enableEagerRootListeners ) {
83
+ // If it is, find the nearest root or portal and make it
84
+ // our event handle target container.
85
+ let targetContainer = getNearestRootOrPortalContainer ( targetFiber ) ;
86
+ if ( targetContainer === null ) {
87
+ if ( __DEV__ ) {
88
+ console . error (
89
+ 'ReactDOM.createEventHandle: setListener called on an target ' +
90
+ 'that did not have a corresponding root. This is likely a bug in React.' ,
91
+ ) ;
92
+ }
93
+ return ;
94
+ }
95
+ if ( targetContainer . nodeType === COMMENT_NODE ) {
96
+ targetContainer = ( ( targetContainer . parentNode : any ) : Element ) ;
97
+ }
98
+ listenToNativeEvent (
99
+ domEventName ,
100
+ isCapturePhaseListener ,
101
+ targetContainer ,
102
+ targetElement ,
98
103
) ;
99
104
}
100
- if ( targetContainer . nodeType === COMMENT_NODE ) {
101
- targetContainer = ( ( targetContainer . parentNode : any ) : Element ) ;
102
- }
103
- listenToNativeEvent (
104
- domEventName ,
105
- isCapturePhaseListener ,
106
- targetContainer ,
107
- targetElement ,
108
- isPassiveListener ,
109
- listenerPriority ,
110
- ) ;
111
105
}
112
106
113
107
function registerReactDOMEvent (
114
108
target : EventTarget | ReactScopeInstance ,
115
109
domEventName : DOMEventName ,
116
- isPassiveListener : boolean | void ,
117
110
isCapturePhaseListener : boolean ,
118
- listenerPriority : EventPriority | void ,
119
111
) : void {
120
112
// Check if the target is a DOM element.
121
113
if ( ( target : any ) . nodeType === ELEMENT_NODE ) {
122
- const targetElement = ( ( target : any ) : Element ) ;
123
- // Check if the DOM element is managed by React.
124
- const targetFiber = getClosestInstanceFromNode ( targetElement ) ;
125
- if ( targetFiber === null ) {
126
- invariant (
127
- false ,
128
- 'ReactDOM.createEventHandle: setListener called on an element ' +
129
- 'target that is not managed by React. Ensure React rendered the DOM element.' ,
114
+ if ( ! enableEagerRootListeners ) {
115
+ const targetElement = ( ( target : any ) : Element ) ;
116
+ // Check if the DOM element is managed by React.
117
+ const targetFiber = getClosestInstanceFromNode ( targetElement ) ;
118
+ if ( targetFiber === null ) {
119
+ if ( __DEV__ ) {
120
+ console . error (
121
+ 'ReactDOM.createEventHandle: setListener called on an element ' +
122
+ 'target that is not managed by React. Ensure React rendered the DOM element.' ,
123
+ ) ;
124
+ }
125
+ return ;
126
+ }
127
+ registerEventOnNearestTargetContainer (
128
+ targetFiber ,
129
+ domEventName ,
130
+ isCapturePhaseListener ,
131
+ targetElement ,
130
132
) ;
131
133
}
132
- registerEventOnNearestTargetContainer (
133
- targetFiber ,
134
- domEventName ,
135
- isPassiveListener ,
136
- listenerPriority ,
137
- isCapturePhaseListener ,
138
- targetElement ,
139
- ) ;
140
134
} else if ( enableScopeAPI && isReactScope ( target ) ) {
141
- const scopeTarget = ( ( target : any ) : ReactScopeInstance ) ;
142
- const targetFiber = getFiberFromScopeInstance ( scopeTarget ) ;
143
- if ( targetFiber === null ) {
144
- // Scope is unmounted, do not proceed.
145
- return ;
135
+ if ( ! enableEagerRootListeners ) {
136
+ const scopeTarget = ( ( target : any ) : ReactScopeInstance ) ;
137
+ const targetFiber = getFiberFromScopeInstance ( scopeTarget ) ;
138
+ if ( targetFiber === null ) {
139
+ // Scope is unmounted, do not proceed.
140
+ return ;
141
+ }
142
+ registerEventOnNearestTargetContainer (
143
+ targetFiber ,
144
+ domEventName ,
145
+ isCapturePhaseListener ,
146
+ null ,
147
+ ) ;
146
148
}
147
- registerEventOnNearestTargetContainer (
148
- targetFiber ,
149
- domEventName ,
150
- isPassiveListener ,
151
- listenerPriority ,
152
- isCapturePhaseListener ,
153
- null ,
154
- ) ;
155
149
} else if ( isValidEventTarget ( target ) ) {
156
150
const eventTarget = ( ( target : any ) : EventTarget ) ;
157
151
// These are valid event targets, but they are also
@@ -161,8 +155,6 @@ function registerReactDOMEvent(
161
155
isCapturePhaseListener ,
162
156
eventTarget ,
163
157
null ,
164
- isPassiveListener ,
165
- listenerPriority ,
166
158
IS_EVENT_HANDLE_NON_MANAGED_NODE ,
167
159
) ;
168
160
} else {
@@ -181,46 +173,27 @@ export function createEventHandle(
181
173
if ( enableCreateEventHandleAPI ) {
182
174
const domEventName = ( ( type : any ) : DOMEventName ) ;
183
175
184
- if ( enableEagerRootListeners ) {
185
- // We cannot support arbitrary native events with eager root listeners
186
- // because the eager strategy relies on knowing the whole list ahead of time.
187
- // If we wanted to support this, we'd have to add code to keep track
188
- // (or search) for all portal and root containers, and lazily add listeners
189
- // to them whenever we see a previously unknown event. This seems like a lot
190
- // of complexity for something we don't even have a particular use case for.
191
- // Unfortunately, the downside of this invariant is that *removing* a native
192
- // event from the list of known events has now become a breaking change for
193
- // any code relying on the createEventHandle API.
194
- invariant (
195
- allNativeEvents . has ( domEventName ) ||
196
- domEventName === 'beforeblur' ||
197
- domEventName === 'afterblur' ,
198
- 'Cannot call unstable_createEventHandle with "%s", as it is not an event known to React.' ,
199
- domEventName ,
200
- ) ;
201
- }
176
+ // We cannot support arbitrary native events with eager root listeners
177
+ // because the eager strategy relies on knowing the whole list ahead of time.
178
+ // If we wanted to support this, we'd have to add code to keep track
179
+ // (or search) for all portal and root containers, and lazily add listeners
180
+ // to them whenever we see a previously unknown event. This seems like a lot
181
+ // of complexity for something we don't even have a particular use case for.
182
+ // Unfortunately, the downside of this invariant is that *removing* a native
183
+ // event from the list of known events has now become a breaking change for
184
+ // any code relying on the createEventHandle API.
185
+ invariant (
186
+ allNativeEvents . has ( domEventName ) ,
187
+ 'Cannot call unstable_createEventHandle with "%s", as it is not an event known to React.' ,
188
+ domEventName ,
189
+ ) ;
202
190
203
191
let isCapturePhaseListener = false ;
204
- let isPassiveListener = undefined ; // Undefined means to use the browser default
205
- let listenerPriority ;
206
-
207
192
if ( options != null ) {
208
193
const optionsCapture = options . capture ;
209
- const optionsPassive = options . passive ;
210
- const optionsPriority = options . priority ;
211
-
212
194
if ( typeof optionsCapture === 'boolean' ) {
213
195
isCapturePhaseListener = optionsCapture ;
214
196
}
215
- if ( typeof optionsPassive === 'boolean' ) {
216
- isPassiveListener = optionsPassive ;
217
- }
218
- if ( typeof optionsPriority === 'number' ) {
219
- listenerPriority = optionsPriority ;
220
- }
221
- }
222
- if ( listenerPriority === undefined ) {
223
- listenerPriority = getEventPriorityForListenerSystem ( domEventName ) ;
224
197
}
225
198
226
199
const eventHandle = (
@@ -234,15 +207,7 @@ export function createEventHandle(
234
207
) ;
235
208
if ( ! doesTargetHaveEventHandle ( target , eventHandle ) ) {
236
209
addEventHandleToTarget ( target , eventHandle ) ;
237
- registerReactDOMEvent (
238
- target ,
239
- domEventName ,
240
- isPassiveListener ,
241
- isCapturePhaseListener ,
242
- listenerPriority ,
243
- ) ;
244
- // Add the event to our known event types list.
245
- addEventTypeToDispatchConfig ( domEventName ) ;
210
+ registerReactDOMEvent ( target , domEventName , isCapturePhaseListener ) ;
246
211
}
247
212
const listener = createEventHandleListener (
248
213
domEventName ,
0 commit comments