Skip to content
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

[RFC] Per React container event listening/dispatching #2050

Closed
wants to merge 1 commit into from

Conversation

chenglou
Copy link
Contributor

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.

@spicyj @zpao @nathansobo

Fixes #2043
Should help with #1964

*/
var topListenersIDKey = "_reactListenersID" + String(Math.random()).slice(2);
// TODO: (chenglou) should we hide this to prevent traversal problem?
var eventsKey = '_reactEvents';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why there is a need to store an object on the DOM node, why not use an internal object indexed by the React ID instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@chenglou
Copy link
Contributor Author

Didn't consider nested renderComponent. Will take care of that later =(.

Edit: seems like it took care of itself in ReactEventListener.handleTopLevelImpl.

@syranide
Copy link
Contributor

👍 This should be a major step towards playing nice with non-React DOM and separate React instances.

@nathansobo
Copy link

Great to see this happening!

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
@chenglou
Copy link
Contributor Author

@nathansobo what else do you need for react atom to get faster?

@chenglou
Copy link
Contributor Author

@nathansobo this is kind of a big change and it's not set in stone. And frankly I'm not even sure how much this helps.

@syranide
Copy link
Contributor

@chenglou It seems to me that it is a critical step towards playing nice with other frameworks and instances.

@nathansobo
Copy link

@chenglou Avoiding event handling for the input field on a per component basis sounds great, but it's "playing nice with other frameworks" that we're interested in more than anything. Performance problems can always be hacked around with manual DOM manipulation if needed, but it would be great to implement individual elements with React without the need for a container.

@autarc
Copy link

autarc commented Feb 15, 2015

Whats the current status of attaching event listeners at react root containers/components instead of the document level ? I've got some issues with 3rd party code interfering with reacts synthetic event system - so their listener callback are triggered as well, although I've tried to use 'e.nativeEvent.stopPropagation()'. Since the review is still open, are there any plans to integrate it or at least provide an option to bind the scope on demand ?

@zpao
Copy link
Member

zpao commented Jul 28, 2015

I think at this point we aren't going to do this. We can revisit later if we need.

@zpao zpao closed this Jul 28, 2015
@fcsonline
Copy link

As @syranide and @autarc said is really difficult to integrate React in existing non React projects if all events are attached to document. We are integrating React in our platform but this issue is breaking expected event bubbling behaviour. It's impossible for us to stop the propagation for some events without hitting other bound libraries.

Before arrive to this issue and understand the current status I built this example to know the impact:

http://jsbin.com/rafitiq/edit?html,js,output

Is there some workaround to make this work properly?

@fcsonline
Copy link

I'm sure that I'm not aware about something that was already discussed but I created this PR and the previous example is working as expected.

@gaearon
Copy link
Collaborator

gaearon commented Aug 11, 2020

We attach events to roots in 17.
https://reactjs.org/blog/2020/08/10/react-v17-rc.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attach event per react container root, rather than on the document
9 participants