What do the bubbles and composed flags mean on a CustomEvent in LWC?
Answer
By default a CustomEvent is non-bubbling and non-composed, so only a direct parent listener on the child element receives it.
- bubbles: true – the event travels up the DOM tree within the same shadow tree.
- composed: true – the event can cross the shadow boundary and propagate into parent shadow trees.
| bubbles | composed | Behaviour |
|---|---|---|
| false | false | Only handlers on the element itself |
| true | false | Bubbles within the same shadow tree |
| true | true | Bubbles and crosses shadow boundaries |
Best practice: keep events non-bubbling/non-composed unless you truly need otherwise, to avoid leaking internal events and coupling components.
lwceventsbubbling