99
1010import type { AnyNativeEvent } from 'legacy-events/PluginModuleType' ;
1111import type { DOMTopLevelEventType } from 'legacy-events/TopLevelEventTypes' ;
12+ import type { ElementListenerMap } from '../events/DOMEventListenerMap' ;
1213import type { EventSystemFlags } from 'legacy-events/EventSystemFlags' ;
14+ import type { EventPriority } from 'shared/ReactTypes' ;
1315import type { Fiber } from 'react-reconciler/src/ReactFiber' ;
1416import type { PluginModule } from 'legacy-events/PluginModuleType' ;
1517import type { ReactSyntheticEvent } from 'legacy-events/ReactSyntheticEventType' ;
@@ -154,9 +156,13 @@ function dispatchEventsForPlugins(
154156export function listenToTopLevelEvent (
155157 topLevelType : DOMTopLevelEventType ,
156158 targetContainer : EventTarget ,
157- listenerMap : Map < DOMTopLevelEventType | string , null | ( any => void ) > ,
159+ listenerMap : ElementListenerMap ,
158160 passive ? : boolean ,
161+ priority ? : EventPriority ,
159162) : void {
163+ // TODO: we need to know if the listenerMap previously was passive
164+ // and to check if we need to upgrade to active. This will come in
165+ // a useEvent follow up PR.
160166 if ( ! listenerMap . has ( topLevelType ) ) {
161167 const isCapturePhase = capturePhaseEvents . has ( topLevelType ) ;
162168 const listener = addTrappedEventListener (
@@ -165,6 +171,7 @@ export function listenToTopLevelEvent(
165171 isCapturePhase ,
166172 false ,
167173 passive ,
174+ priority ,
168175 ) ;
169176 listenerMap . set ( topLevelType , listener ) ;
170177 }
@@ -354,7 +361,7 @@ function getNearestRootOrPortalContainer(instance: Element): Element {
354361
355362export function attachElementListener ( listener : ReactDOMListener ) : void {
356363 const { event, target} = listener ;
357- const { passive, type} = event ;
364+ const { passive, priority , type} = event ;
358365 let containerEventTarget = target ;
359366 // If we the target is a managed React element, then we need to
360367 // find the nearest root/portal contained to attach the event listener
@@ -376,6 +383,7 @@ export function attachElementListener(listener: ReactDOMListener): void {
376383 containerEventTarget ,
377384 listenerMap ,
378385 passive ,
386+ priority ,
379387 ) ;
380388 // Get the internal listeners Set from the target instance.
381389 let listeners = getListenersFromTarget ( target ) ;
0 commit comments