-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Don't add top-level events for uncontrolled inputs #1964
Comments
React should only attach top-level handlers for events that you're using in your components – are you seeing otherwise? |
@nathansobo I'm curious whether it is the simulated dispatcher (i.e, capturing, bubbling, etc) or the initialization of the synthetic event that is most costly for you. I assume it is the simulated dispatcher, which currently does a lot of ugly string hacking to do its thing (chenglou is working on that I believe). While the |
Also, you can easily opt-out of React's event dispatcher by just not using it and calling PS. I imagine that since you're operating in a single modern and fast environment, React's entire event dispatcher is quite redundant for you, you could probably just replace it internally with immediate calls to |
@nathansobo Ah, that explains it. Yeah, So if you're using uncontrolled inputs, it's probably something we should have a look at to see if it can avoided. If you're using controlled inputs, your best bet is probably to implement your own controlled inputs on-top of uncontrolled inputs (again, we should have a look at if the change handler can be avoided for them). However, you can remove As for using native APIs directly, I'm not super familiar with the event system code in React. But apart from (You probably want to remove |
Thanks for your thoughtful explanation here. Yeah, this input definitely uncontrolled. It's not even visible, but just exists to receive input which we render ourselves in the editor. For now, stopping propagation of I'm hesitant to remove controlled inputs entirely in case users want to use them elsewhere. For now we're exporting our copy of React to users until the multiple-instance issue is addressed, so I'd like inputs to work as expected for them. Not sure disabling the synthetic event system is warranted yet, but if we see it costing us time elsewhere I'll definitely take a crack at it. I'm going to close this now. Thanks for the conversation! |
Pretty sure we don't need to attach the event handlers for uncontrolled components. I'll check and let you know. |
@nathansobo If you're stopping propagation of That being said, the synthetic event system in React exists for two reasons AFAIK:
1 should be irrelevant for you, and 2 is probably not as important for you as you're in a faster modern environment. Also, dropping frames is far more noticeable (as you say) than a popup taking a few frames longer to open in worst-case. Just food for thought. I definitely see Atom becoming my one-and-only editor in the future, so I'm just happy to help. :) |
Fixes facebook#1964. Test Plan: jest. Also verified that the ballmer-peak example still works and works when changed to use a textarea or select, but that if the input is changed to an uncontrolled component with no onChange, that Chrome doesn't list the event handlers bound in the Elements > Event Listeners panel.
Just made #1968 with a possible fix, though I'm unsure how well I like it. |
Work in progress. `enterleave` plugin (and maybe `analyticsPlugin`) is broken because it relied on the old behavior. But wanted to put this out here for suggestions. There are also some comments that need to be changed, I'll do it when the code is finalized. If we attach the event listening/dispatching at container level, it'll benefit the case of `<Editor/><Plugin1/>` (both are container roots), since `Plugin1` won't disturb `Editor`. We also detach those listeners now. There wasn't really a need in the past. Fixes facebook#2043 Should help with facebook#1964
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
The document-wide handlers for native events that perform synthetic event dispatch execute in 0.2-0.7 milliseconds on my machine. I realize this doesn't seem like much time, but we're really trying to shave off any non-essential source of latency for typing and cursor movement in Atom, and every little bit helps. Disabling synthetic events on
keydown
andtextinput
is saving about 1ms of latency for a keystroke.In our fork, I've added the ability to add a
reactSkipEventDispatch
property to the native event to opt out of synthetic dispatch, but I'd be interested in a more official mechanism for opting out of this feature for certain event types. Even better, perhaps React could maintain a cache of what event types are actually being listened for and bail out as soon as possible if handling an event.The text was updated successfully, but these errors were encountered: