react / react/react

Bug: Events in shadow dom get duplicated when bubbling

Open
#24,136 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: DOM Status: Unconfirmed Type: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.