Bug: Events in shadow dom get duplicated when bubbling
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 251k
- Forks
- 51.4k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 53
Description
Events dispatching from inside a shadow-root will be handled multiple times while bubbling up the virtual DOM tree. I suspect this is because of event retargeting when crossing the boundary of the shadow dom.
React version: 17.0+, including 18-rc2
Steps To Reproduce
Click on the button in the code example below:
https://codesandbox.io/s/react-shadow-dom-event-doubling-msgnj1
The current behavior
onDivClicked is called twice per click on the button.
The expected behavior
onDivClicked should only be called once per handled click.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and inspect how the click moves across the shadow-root boundary in React 17 and 18. Done means onDivClicked is invoked once per button click while the event bubbles, with the reproduced case covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100