-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine event registration + event signatures #19244
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 0709a3c:
|
Details of bundled changes.Comparing: 65c1377...0709a3c react-dom
ReactDOM: size: 0.0%, gzip: -0.1% Size changes (experimental) |
Details of bundled changes.Comparing: 65c1377...0709a3c react-dom
ReactDOM: size: 0.0%, gzip: -0.1% Size changes (stable) |
@@ -904,17 +918,16 @@ export function accumulateEventTargetListeners( | |||
if (eventListeners !== null) { | |||
const listenersArr = Array.from(eventListeners); | |||
const targetType = ((event.type: any): DOMTopLevelEventType); | |||
const isCapturePhase = (event: any).eventPhase === 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a significant change. Instead of reading this from the event, we now pass it from outside based on whether it's in a list. Can you please explain why this is a refactoring rather than a semantic change? And what does it accomplish, exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there are two things here to note:
- This code is only used with
createEventHandle
logic, so this isn't that much of a significant change given we have no product code anywhere that uses this code path right now. - It avoids us having to rely on
eventPhase
which can change if you add a listener to a node and the listener triggers on it (which would meaneventPhase
is2
, even if it were a capture phase). When we setup the listener we can add this information to the event flags as a detail, completely avoiding this check.
!isListeningToEvents(rootTargetDependencies, targetContainer)) | ||
topLevelType !== TOP_SELECTION_CHANGE && | ||
!eventListenerMap.has('onSelect') && | ||
!eventListenerMap.has('onSelectCapture') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this check is equivalent? It's not obvious to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than going through all the dependencies one by one, we can instead check if we've registered onSelect
or onSelectCapture
. The dependencies are both the same, as we listen to the same events for both onSelect
and onSelectCapture
.
Note: This PR was rebased on top of #19244.
In an attempt to break up the amount of changes in #19221, I decied to pull out the logic that was not strictly related to moving to the
capture
phase for events. This was mostly logic around handling event registration and the some of the clean up around the event workflow. This should hopefully make the other PR smaller and simpler to understand once it gets rebased on top of this PR.