-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Re-added support for attaching events to document fragments #6462
Conversation
@Wildhoney What will happen if you mount into a div that lives in a document fragment? Will this do the right thing, or do we need to walk up toward the top to discover the fragment that we live within? |
As far as I can see, the |
I talked with @spicyj on internal chat, he just didn't know it was a use case. I don't think there is any reason not to support this. My question though was with regard to ensuring that the document fragment gets selected as the document if we are mounting into a div within that document fragment.
In this case, we are mounting into the |
Specifically, I'm concerned that |
Ah β you're right. const shadowRoot = findDOMNode(this).attachShadow({ mode: 'open' });
const container = <span onClick={() => console.log('...')}>Node</span>;
const divNode = shadowRoot.appendChild(document.createElement('div'));
render(container, divNode); Which doesn't handle the I've tried to err on the side of caution with |
Yeah, ok, I buy that. I'll accept to fix the regression. We should handle the other case at some point. Would you be willing/interested in doing a followup PR to handle that? |
Absolutely β if I can find a way to select |
@Wildhoney Ideally there would be a fast/easy way to get it directly. Worst case, it might require walking up the DOM nodes' parentNode until you find a document/fragment (or null). Obviously we'd only want to do that on initial mount and cache the value (maybe emit a warning if we can't find a good root). |
I'm slightly wary of the latter, as it seems to be an expensive task for what is possibly an edge-case. Nevertheless, thanks for your help @jimfb β leave it with me π |
In React 0.14 there was an approach to enable event.path handling in ReactEventListener. This function was removed in React 15. Previously we had to switch the comment block in handleTopLevelImpl in order to enable event handling capabilities in shadow-dom. Thanks, |
Re-added support for attaching events to document fragments (cherry picked from commit 0b1fd18)
Event bindings (like onClick for a button) don't work in React (15.4.2) within a shadow root. It seemed like that issue was going to be resolved from this convo - is there any progress happening to fix that issue that someone could like me to? Thanks |
I thought I'd jump straight in and make the change π
In the open issue it was mentioned that @spicyj wrote this part of the code, so it would be awesome if he β or anybody else β could chime in about the optimal way of implementing this. Thanks!