GeezerVison is showing github.com — Add container to event listener signature (#18075) · react/react@1000f61
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/ReactGenericBatching.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,8 +23,8 @@ import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils'; | 23 | 23 | let batchedUpdatesImpl = function(fn, bookkeeping) { | 24 | 24 | return fn(bookkeeping); | 25 | 25 | }; | 26 | | -let discreteUpdatesImpl = function(fn, a, b, c) { | 27 | | - return fn(a, b, c); | | 26 | +let discreteUpdatesImpl = function(fn, a, b, c, d) { | | 27 | + return fn(a, b, c, d); | 28 | 28 | }; | 29 | 29 | let flushDiscreteUpdatesImpl = function() {}; | 30 | 30 | let batchedEventUpdatesImpl = batchedUpdatesImpl; | @@ -89,11 +89,11 @@ export function executeUserEventHandler(fn: any => void, value: any): void { | 89 | 89 | } | 90 | 90 | } | 91 | 91 |
| 92 | | -export function discreteUpdates(fn, a, b, c) { | | 92 | +export function discreteUpdates(fn, a, b, c, d) { | 93 | 93 | const prevIsInsideEventHandler = isInsideEventHandler; | 94 | 94 | isInsideEventHandler = true; | 95 | 95 | try { | 96 | | - return discreteUpdatesImpl(fn, a, b, c); | | 96 | + return discreteUpdatesImpl(fn, a, b, c, d); | 97 | 97 | } finally { | 98 | 98 | isInsideEventHandler = prevIsInsideEventHandler; | 99 | 99 | if (!isInsideEventHandler) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/ReactDOMEventListener.js +45-8Lines changed: 45 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,6 +119,7 @@ export function addResponderEventSystemEvent( | 119 | 119 | null, | 120 | 120 | ((topLevelType: any): DOMTopLevelEventType), | 121 | 121 | eventFlags, | | 122 | + document, | 122 | 123 | ); | 123 | 124 | if (passiveBrowserEventsSupported) { | 124 | 125 | addEventCaptureListenerWithPassiveFlag( | @@ -149,7 +150,7 @@ export function removeActiveResponderEventSystemEvent( | 149 | 150 | } | 150 | 151 |
| 151 | 152 | function trapEventForPluginEventSystem( | 152 | | - element: Document | Element | Node, | | 153 | + container: Document | Element | Node, | 153 | 154 | topLevelType: DOMTopLevelEventType, | 154 | 155 | capture: boolean, | 155 | 156 | ): void { | @@ -160,48 +161,74 @@ function trapEventForPluginEventSystem( | 160 | 161 | null, | 161 | 162 | topLevelType, | 162 | 163 | PLUGIN_EVENT_SYSTEM, | | 164 | + container, | 163 | 165 | ); | 164 | 166 | break; | 165 | 167 | case UserBlockingEvent: | 166 | 168 | listener = dispatchUserBlockingUpdate.bind( | 167 | 169 | null, | 168 | 170 | topLevelType, | 169 | 171 | PLUGIN_EVENT_SYSTEM, | | 172 | + container, | 170 | 173 | ); | 171 | 174 | break; | 172 | 175 | case ContinuousEvent: | 173 | 176 | default: | 174 | | - listener = dispatchEvent.bind(null, topLevelType, PLUGIN_EVENT_SYSTEM); | | 177 | + listener = dispatchEvent.bind( | | 178 | + null, | | 179 | + topLevelType, | | 180 | + PLUGIN_EVENT_SYSTEM, | | 181 | + container, | | 182 | + ); | 175 | 183 | break; | 176 | 184 | } | 177 | 185 |
| 178 | 186 | const rawEventName = getRawEventName(topLevelType); | 179 | 187 | if (capture) { | 180 | | - addEventCaptureListener(element, rawEventName, listener); | | 188 | + addEventCaptureListener(container, rawEventName, listener); | 181 | 189 | } else { | 182 | | - addEventBubbleListener(element, rawEventName, listener); | | 190 | + addEventBubbleListener(container, rawEventName, listener); | 183 | 191 | } | 184 | 192 | } | 185 | 193 |
| 186 | | -function dispatchDiscreteEvent(topLevelType, eventSystemFlags, nativeEvent) { | | 194 | +function dispatchDiscreteEvent( | | 195 | + topLevelType, | | 196 | + eventSystemFlags, | | 197 | + container, | | 198 | + nativeEvent, | | 199 | +) { | 187 | 200 | flushDiscreteUpdatesIfNeeded(nativeEvent.timeStamp); | 188 | | - discreteUpdates(dispatchEvent, topLevelType, eventSystemFlags, nativeEvent); | | 201 | + discreteUpdates( | | 202 | + dispatchEvent, | | 203 | + topLevelType, | | 204 | + eventSystemFlags, | | 205 | + container, | | 206 | + nativeEvent, | | 207 | + ); | 189 | 208 | } | 190 | 209 |
| 191 | 210 | function dispatchUserBlockingUpdate( | 192 | 211 | topLevelType, | 193 | 212 | eventSystemFlags, | | 213 | + container, | 194 | 214 | nativeEvent, | 195 | 215 | ) { | 196 | 216 | runWithPriority( | 197 | 217 | UserBlockingPriority, | 198 | | - dispatchEvent.bind(null, topLevelType, eventSystemFlags, nativeEvent), | | 218 | + dispatchEvent.bind( | | 219 | + null, | | 220 | + topLevelType, | | 221 | + eventSystemFlags, | | 222 | + container, | | 223 | + nativeEvent, | | 224 | + ), | 199 | 225 | ); | 200 | 226 | } | 201 | 227 |
| 202 | 228 | export function dispatchEvent( | 203 | 229 | topLevelType: DOMTopLevelEventType, | 204 | 230 | eventSystemFlags: EventSystemFlags, | | 231 | + container: Document | Element | Node, | 205 | 232 | nativeEvent: AnyNativeEvent, | 206 | 233 | ): void { | 207 | 234 | if (!_enabled) { | @@ -216,6 +243,7 @@ export function dispatchEvent( | 216 | 243 | topLevelType, | 217 | 244 | eventSystemFlags, | 218 | 245 | nativeEvent, | | 246 | + container, | 219 | 247 | ); | 220 | 248 | return; | 221 | 249 | } | @@ -224,6 +252,7 @@ export function dispatchEvent( | 224 | 252 | topLevelType, | 225 | 253 | eventSystemFlags, | 226 | 254 | nativeEvent, | | 255 | + container, | 227 | 256 | ); | 228 | 257 |
| 229 | 258 | if (blockedOn === null) { | @@ -234,7 +263,13 @@ export function dispatchEvent( | 234 | 263 |
| 235 | 264 | if (isReplayableDiscreteEvent(topLevelType)) { | 236 | 265 | // This this to be replayed later once the target is available. | 237 | | - queueDiscreteEvent(blockedOn, topLevelType, eventSystemFlags, nativeEvent); | | 266 | + queueDiscreteEvent( | | 267 | + blockedOn, | | 268 | + topLevelType, | | 269 | + eventSystemFlags, | | 270 | + nativeEvent, | | 271 | + container, | | 272 | + ); | 238 | 273 | return; | 239 | 274 | } | 240 | 275 |
| @@ -244,6 +279,7 @@ export function dispatchEvent( | 244 | 279 | topLevelType, | 245 | 280 | eventSystemFlags, | 246 | 281 | nativeEvent, | | 282 | + container, | 247 | 283 | ) | 248 | 284 | ) { | 249 | 285 | return; | @@ -289,6 +325,7 @@ export function attemptToDispatchEvent( | 289 | 325 | topLevelType: DOMTopLevelEventType, | 290 | 326 | eventSystemFlags: EventSystemFlags, | 291 | 327 | nativeEvent: AnyNativeEvent, | | 328 | + container: Document | Element | Node, | 292 | 329 | ): null | Container | SuspenseInstance { | 293 | 330 | // TODO: Warn if _enabled is false. | 294 | 331 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/ReactDOMEventReplaying.js +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,7 @@ type QueuedReplayableEvent = {| | 124 | 124 | topLevelType: DOMTopLevelEventType, | 125 | 125 | eventSystemFlags: EventSystemFlags, | 126 | 126 | nativeEvent: AnyNativeEvent, | | 127 | + container: Document | Element | Node, | 127 | 128 | |}; | 128 | 129 |
| 129 | 130 | let hasScheduledReplayAttempt = false; | @@ -252,12 +253,14 @@ function createQueuedReplayableEvent( | 252 | 253 | topLevelType: DOMTopLevelEventType, | 253 | 254 | eventSystemFlags: EventSystemFlags, | 254 | 255 | nativeEvent: AnyNativeEvent, | | 256 | + container: Document | Element | Node, | 255 | 257 | ): QueuedReplayableEvent { | 256 | 258 | return { | 257 | 259 | blockedOn, | 258 | 260 | topLevelType, | 259 | 261 | eventSystemFlags: eventSystemFlags | IS_REPLAYED, | 260 | 262 | nativeEvent, | | 263 | + container, | 261 | 264 | }; | 262 | 265 | } | 263 | 266 |
| @@ -266,12 +269,14 @@ export function queueDiscreteEvent( | 266 | 269 | topLevelType: DOMTopLevelEventType, | 267 | 270 | eventSystemFlags: EventSystemFlags, | 268 | 271 | nativeEvent: AnyNativeEvent, | | 272 | + container: Document | Element | Node, | 269 | 273 | ): void { | 270 | 274 | const queuedEvent = createQueuedReplayableEvent( | 271 | 275 | blockedOn, | 272 | 276 | topLevelType, | 273 | 277 | eventSystemFlags, | 274 | 278 | nativeEvent, | | 279 | + container, | 275 | 280 | ); | 276 | 281 | queuedDiscreteEvents.push(queuedEvent); | 277 | 282 | if (enableSelectiveHydration) { | @@ -339,6 +344,7 @@ function accumulateOrCreateContinuousQueuedReplayableEvent( | 339 | 344 | topLevelType: DOMTopLevelEventType, | 340 | 345 | eventSystemFlags: EventSystemFlags, | 341 | 346 | nativeEvent: AnyNativeEvent, | | 347 | + container: Document | Element | Node, | 342 | 348 | ): QueuedReplayableEvent { | 343 | 349 | if ( | 344 | 350 | existingQueuedEvent === null || | @@ -349,6 +355,7 @@ function accumulateOrCreateContinuousQueuedReplayableEvent( | 349 | 355 | topLevelType, | 350 | 356 | eventSystemFlags, | 351 | 357 | nativeEvent, | | 358 | + container, | 352 | 359 | ); | 353 | 360 | if (blockedOn !== null) { | 354 | 361 | let fiber = getInstanceFromNode(blockedOn); | @@ -372,6 +379,7 @@ export function queueIfContinuousEvent( | 372 | 379 | topLevelType: DOMTopLevelEventType, | 373 | 380 | eventSystemFlags: EventSystemFlags, | 374 | 381 | nativeEvent: AnyNativeEvent, | | 382 | + container: Document | Element | Node, | 375 | 383 | ): boolean { | 376 | 384 | // These set relatedTarget to null because the replayed event will be treated as if we | 377 | 385 | // moved from outside the window (no target) onto the target once it hydrates. | @@ -385,6 +393,7 @@ export function queueIfContinuousEvent( | 385 | 393 | topLevelType, | 386 | 394 | eventSystemFlags, | 387 | 395 | focusEvent, | | 396 | + container, | 388 | 397 | ); | 389 | 398 | return true; | 390 | 399 | } | @@ -396,6 +405,7 @@ export function queueIfContinuousEvent( | 396 | 405 | topLevelType, | 397 | 406 | eventSystemFlags, | 398 | 407 | dragEvent, | | 408 | + container, | 399 | 409 | ); | 400 | 410 | return true; | 401 | 411 | } | @@ -407,6 +417,7 @@ export function queueIfContinuousEvent( | 407 | 417 | topLevelType, | 408 | 418 | eventSystemFlags, | 409 | 419 | mouseEvent, | | 420 | + container, | 410 | 421 | ); | 411 | 422 | return true; | 412 | 423 | } | @@ -421,6 +432,7 @@ export function queueIfContinuousEvent( | 421 | 432 | topLevelType, | 422 | 433 | eventSystemFlags, | 423 | 434 | pointerEvent, | | 435 | + container, | 424 | 436 | ), | 425 | 437 | ); | 426 | 438 | return true; | @@ -436,6 +448,7 @@ export function queueIfContinuousEvent( | 436 | 448 | topLevelType, | 437 | 449 | eventSystemFlags, | 438 | 450 | pointerEvent, | | 451 | + container, | 439 | 452 | ), | 440 | 453 | ); | 441 | 454 | return true; | @@ -512,6 +525,7 @@ function attemptReplayContinuousQueuedEvent( | 512 | 525 | queuedEvent.topLevelType, | 513 | 526 | queuedEvent.eventSystemFlags, | 514 | 527 | queuedEvent.nativeEvent, | | 528 | + queuedEvent.container, | 515 | 529 | ); | 516 | 530 | if (nextBlockedOn !== null) { | 517 | 531 | // We're still blocked. Try again later. | @@ -554,6 +568,7 @@ function replayUnblockedEvents() { | 554 | 568 | nextDiscreteEvent.topLevelType, | 555 | 569 | nextDiscreteEvent.eventSystemFlags, | 556 | 570 | nextDiscreteEvent.nativeEvent, | | 571 | + nextDiscreteEvent.container, | 557 | 572 | ); | 558 | 573 | if (nextBlockedOn !== null) { | 559 | 574 | // We're still blocked. Try again later. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/test-utils/ReactTestUtils.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,7 @@ let hasWarnedAboutDeprecatedMockComponent = false; | 62 | 62 | */ | 63 | 63 | function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) { | 64 | 64 | fakeNativeEvent.target = node; | 65 | | - dispatchEvent(topLevelType, PLUGIN_EVENT_SYSTEM, fakeNativeEvent); | | 65 | + dispatchEvent(topLevelType, PLUGIN_EVENT_SYSTEM, document, fakeNativeEvent); | 66 | 66 | } | 67 | 67 |
| 68 | 68 | /** | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1160,17 +1160,18 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R { | 1160 | 1160 | } | 1161 | 1161 | } | 1162 | 1162 |
| 1163 | | -export function discreteUpdates<A, B, C, R>( | | 1163 | +export function discreteUpdates<A, B, C, D, R>( | 1164 | 1164 | fn: (A, B, C) => R, | 1165 | 1165 | a: A, | 1166 | 1166 | b: B, | 1167 | 1167 | c: C, | | 1168 | + d: D, | 1168 | 1169 | ): R { | 1169 | 1170 | const prevExecutionContext = executionContext; | 1170 | 1171 | executionContext |= DiscreteEventContext; | 1171 | 1172 | try { | 1172 | 1173 | // Should this | 1173 | | - return runWithPriority(UserBlockingPriority, fn.bind(null, a, b, c)); | | 1174 | + return runWithPriority(UserBlockingPriority, fn.bind(null, a, b, c, d)); | 1174 | 1175 | } finally { | 1175 | 1176 | executionContext = prevExecutionContext; | 1176 | 1177 | if (executionContext === NoContext) { | |
|