Development questions

What do the bubbles and composed flags mean on a CustomEvent in LWC?

DevelopmentMedium

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.
bubblescomposedBehaviour
falsefalseOnly handlers on the element itself
truefalseBubbles within the same shadow tree
truetrueBubbles 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