Issue 1:
We need to host a standalone React component (DraftJS editor) inside a HTML5 application which will run on other JS framework, or even plain JS or jQuery.

The code of the application is beyond our control, we are just a vendor of a component which adds some content, part of which is this React-based editor.

Anyway, the most important part is that we need to add the component with the following code to an existing DIV.

const editor = ReactDOM.render(
React.createElement(
EditorComponent,
props
),
divElem
);

EditorComponent is a regular React component with some onClick events attached to its content (primarily toolbar buttons for the editor).

I learned that React event model and its bubbling executes independently after the event bubbles all the way up to the document, and that if ev.stopPropagation() is called on native event, React events won't execute at all.

That is understandable for situations where document contains only the React app / component at its root and no other content, meaning you have control over all events on the page from React code.

However, when React component is just a small fraction of the entire page, it may be severely influenced by the rest of the page.

The problem is that any event handling code above the component which calls ev.stopPropagation() cuts of the events of that smaller fraction, even that the event originated from the React component scope.

That influencing code could very well be just some jQuery plugin, so even author of the page may not be able to rewrite their code for some special event handling.

Here is a fiddle to demonstrate that: https://jsfiddle.net/martinh_kentico/kept9anh/3/

I believe that the point where the event chain breaks, allowing React to execute its events, should be the root element of React component, rather than the whole document.

This way, React root element could be considered an isolation edge of the React application / component.

I tracked the React event registration down to function ReactDOMComponent.ensureListeningTo(...) where I found the following code:

var doc = isDocumentFragment ? containerInfo._node : containerInfo._ownerDocument;
listenTo(registrationName, doc);

I tried to change containerInfo._ownerDocument to containerInfo._node to register the React event chain to the root of the React container, and tried it for several basic events (onClick, onMouseDown/Up) and it seems working for us as expected.

React events are not influenced by stopping propagation at the native events outside of React component root, so the two differently implemented parts of the application can coexist in peace.

I am not sure why _ownerDocument was chosen over _node in the implementation and if changing it to _node could break something important.

Please advise if the proposed solution seems viable (in that case consider a change to that), or for what reasons you wouldn't recommend it.

Issue 2:
@nathansobo will that help your event perf issues a bit? I'm not familiar with atom's plugin infrastructure, But this'll help if you have <Editor/><Plugin1/> (two renderComponents). Doesn't help if you have <Editor><Plugin1/></Editor> though, but I have some ideas to optimize events a bit more.

This is nonetheless an ok idea, I think.

@spicyj