A Lightning Web Component needs to communicate an event to a grandparent component that is several levels up in the DOM tree. Which mechanism should be used?
Trap 1: Standard component events via aura:registerEvent
Component events only bubble up parent-child hierarchies in Aura.
Trap 2: Standard window.postMessage API
window.postMessage is not recommended or standard for LWC intra-page communication.
Trap 3: Imperative Apex method calls
Apex methods are for server communication, not local component messaging.
- A
CustomEvent with bubbles: true and composed: true
Custom events with composed:true can cross shadow DOM boundaries to reach ancestors.
- B
Standard component events via aura:registerEvent
Why wrong: Component events only bubble up parent-child hierarchies in Aura.
- C
Standard window.postMessage API
Why wrong: window.postMessage is not recommended or standard for LWC intra-page communication.
- D
Imperative Apex method calls
Why wrong: Apex methods are for server communication, not local component messaging.