-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Event not invoked in ShadowDom's non-root node. #15759
Comments
If anyone interested, here is a hack that can resolve problems by event lost due to ShadowRoot. {
// ? Hack for React, let event go through ShadowDom
const hackingEvents = new WeakMap()
function hack(eventName, shadowRoot) {
shadowRoot.addEventListener(eventName, e => {
if (hackingEvents.has(e)) return
const path = e.composedPath()
var e2 = new e.constructor(e.type, e)
hackingEvents.set(e2, path)
shadowRoot.dispatchEvent(e2)
e.stopPropagation()
e.stopImmediatePropagation()
})
}
// call hack with parameter1 = Event name you want to make it work with ShadowRoot
// parameter2 = the shadow root
hack('click', portal)
var nativeTarget = Object.getOwnPropertyDescriptor(Event.prototype, 'target').get
Object.defineProperty(Event.prototype, 'target', {
get() {
if (hackingEvents.has(this)) return hackingEvents.get(this)[0]
return nativeTarget.call(this)
}
})
} |
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. |
Wait. This bug is not fixed yet. Don't close it. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any additional information, please include with in your comment! |
Don't close |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Let me try if it is fixed in react 17 later |
resolved in 17.0.0-rc.3 |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The second h1 onClick not responding
Reproduce:
What is the expected behavior?
The first h1 works, the second h1 works too.
The text was updated successfully, but these errors were encountered: