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.
| 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
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?