I'm facing some issues when rendering a React component into the shadow DOM of a webcomponent. I wrote a small piece of code to turn a React component into a webcomponent, but I want to render the React component inside the shadow DOM of the webcomponent. But in that case, it seems that React is not able to catch UI events (click, keyPress, etc ...) anymore.
Let's take an example, let say that I have a first webcomponent <awesome-timer />
that render the React component inside the webcomponent node, and another webcomponent <less-awesome-timer />
that render the React component inside the shadow DOM of the webcomponent.
Both webcomponents use the same React component. However the one rendered inside the shadow DOM does not work, because click events on the button of the timer component does not trigger the bound function.
I guess React is not designed to handle such case, but I'd love to get more details about it.
The code of the example is available here : https://gist.github.com/mathieuancelin/cca14d31184bf4468bc1
Does anyone have an idea about it ?
click
event is prevented from bubbling, this doesn't work because shadow DOM events that bubble are retargeted to the shadow root. This seems impossible to workaround because the root React event listener receives a click event from a non-React element. – Sensor