-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Add container to event listener signature #18075
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. |
Details of bundled changes.Comparing: f48a5e6...539baea react-dom
ReactDOM: size: 0.0%, gzip: -0.0% Size changes (stable) |
b65f791
to
539baea
Compare
Details of bundled changes.Comparing: f48a5e6...539baea react-dom
Size changes (experimental) |
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.
The order of arguments across functions can be quite confusing 😅
@@ -289,6 +325,7 @@ export function attemptToDispatchEvent( | |||
topLevelType: DOMTopLevelEventType, | |||
eventSystemFlags: EventSystemFlags, | |||
nativeEvent: AnyNativeEvent, | |||
container: Document | Element | Node, |
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.
All of the other signatures have it before nativeEvent
so this was a bit confusing.
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 the ones below don't. It would be nice to preserve a consistent order because it's easy to mix them up. Hopefully Flow would catch that.
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.
Flow can catch it, and it did, because I've hacked this file abount so much in the last few days and it's saved my ass a bunch :)
I can refine the order in a follow up though, you're right, consistency helps here.
Note: This PR is a pre-requisite for the modern root event system.
For the new event system that uses root containers to register nodes. For this to work, we need a sane way of knowing what the container is, so we can properly find ancestors.
We could use
nativeEvent.currentTarget
but that seems fragile, as thecurrentTarget
can change when the event bubbles, or might not be there if we bypass native events entirely (if we ever decided to addonBeforeBlur
to the plugin event system).Instead, we can bind the
container
to the dispatch function, as we do with other arguments. This then allows us to know the container correctly in all cases. Furthermore, we pass this to the event replaying logic so it can properly replay the event with the correctcontainer
.