Skip to main content

Connecting LWC and Aura Components Using Aura Events: Complete Integration Guide

In plain words: When upgrading an older Salesforce application, you often need modern Lightning Web Components (LWC) to talk to legacy Aura components. Because they use different architectural frameworks, Salesforce allows LWC to dispatch standard custom events that parent Aura components can listen to, enabling seamless interoperability.

As organizations transition their Salesforce user interfaces from legacy Aura components to modern Lightning Web Components (LWC), hybrid applications are common. Ensuring smooth communication between these two architectures is essential. While LWC components cannot directly listen to Aura component events, Aura components can easily wrap and listen to standard DOM events dispatched by LWC child components.

1. Understanding LWC-to-Aura Interoperability

Bridging the gap between LWC and Aura requires following specific component integration patterns:

  • Aura Hosting LWC: An Aura component can include an LWC component directly in its markup like any standard child element.
  • Event Dispatching from LWC: The LWC child component uses standard JavaScript CustomEvent and this.dispatchEvent() to broadcast data upward.
  • Aura Event Handling: The wrapping Aura component captures the event using standard attribute handlers (onfieldname={c.handleMethod}).
360 Interoperability Architecture Card:
  • Directional Rule: LWC can communicate with parent Aura components via DOM events; Aura cannot directly dispatch events into LWC without Lightning Message Service.
  • Event Bubbling: Ensure LWC events have bubbles: true and composed: true enabled to cross shadow DOM boundaries.
  • Data Payload: Pass parameters inside the detail property object of the JavaScript CustomEvent.
  • Modern Alternative: For decoupled, unnested components, prefer Lightning Message Service (LMS) over Aura Events.

2. Step-by-Step Implementation: LWC Dispatched to Aura Parent

Step 1: Dispatching the Event from LWC
The LWC component creates a custom event and dispatches it upward with data.
// lwcChild.js
import { LightningElement } from 'lwc';

export default class LwcChild extends LightningElement {
    handleNotification() {
        const myEvent = new CustomEvent('notifyaura', {
            detail: { message: 'Hello from Lightning Web Component!' },
            bubbles: true,
            composed: true
        });
        this.dispatchEvent(myEvent);
    }
}
Step 2: Catching the Event in the Aura Parent Component
The Aura component wraps the LWC tag and binds the event handler using the on prefix combined with the lowercase event name.
<!-- auraParent.cmp -->
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="statusMessage" type="String" default="Waiting for event..." />

    <lightning:card title="Aura Parent Container">
        <div class="slds-p-around_medium">
            <p>Status: <aura:text value="{!v.statusMessage}" /></p>
            
            <!-- Include LWC component and bind event listener (onnotifyaura) -->
            <c:lwcChild onnotifyaura="{!c.handleLwcEvent}" />
        </div>
    </lightning:card>
</aura:component>
Step 3: Aura Controller Processing the Event Payload
Reading the event details inside the Aura controller client-side action.
// auraParentController.js
({
    handleLwcEvent : function(component, event, helper) {
        // Extract data passed from LWC via event.getParam('message') or event.getParam('detail')
        var eventDetails = event.getParam('message');
        component.set("v.statusMessage", eventDetails);
    }
})

3. Common Developer Traps & Best Practices

Developer Trap: Forgetting composed: true
Because Lightning Web Components operate inside shadow DOM boundaries, events dispatched from LWC do not bubble past shadow roots by default. If your LWC component is wrapped inside an Aura component, omitting composed: true in your CustomEvent configuration will prevent the Aura parent from ever capturing the event.
Core Rule: When LWC components need to communicate with parent Aura components, dispatch a CustomEvent with bubbles: true and composed: true enabled.
  • Plan for Full Migration: While LWC-to-Aura interoperability supports legacy refactoring, prioritize migrating remaining Aura components to pure LWC to take advantage of modern performance and web standards.
  • Use Lightning Message Service for Sibling Components: If your LWC and Aura components are not in a direct parent-child hierarchy, use Lightning Message Service (LMS) to broadcast messages across both contexts.

Summary

Connecting Lightning Web Components and Aura components via custom events bridges the gap between legacy and modern Salesforce architectures. By configuring CustomEvent objects with proper bubbling and composition rules, developers can ensure smooth interoperability and data flow across hybrid Salesforce applications.