function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jason SippieJason Sippie 

Application event fired multiple times

I'm having an issue with Spring '07 Lightning Application Events. It seems that handlers of an application event are being notified multiple times for a single firing of the event. This can be replicated on various browsers. 

How to reproduce the error:
1) Create the below components and put them in a new lightning page for an object of your choice. 
2) Assign that page to a profile, app or org
3) Navigate to that object's list view and then drill down to the newly created page
4) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event

5) Navigate back to the list view and drill down on another record
6) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event
Test2 receiving event
Test1 receiving event

7) If you repeat steps 5 and 6, you will get an additional two lines in the console for each time you repeat the process. I.e., one firing of the event is causing the handlers to be notified multiple times. 

Incidentally, I don't have this problem in the community edition. It's only in the base lightning experience version that it crops up. Can anyone replicate this? Thanks. 

Component #1
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    <aura:registerEvent name="stateControlEvent" type="c:pvStateControlEvt"/>

I send and receive events
            <lightning:button label="sendEvent" aura:id="testButton" onclick="{!c.fireEvent}"/>

</aura:component>

Component #1 controller
({
fireEvent : function(component, event, helper) {
       var theEvent = $A.get("e.c:pvStateControlEvt");
        theEvent.fire();

},
receiveEvent : function(component, event, helper) {
        console.log("Test1 receiving event");
    }
})


Component #2
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    I receive events
</aura:component>

Component #2 controller
({
receiveEvent : function(component, event, helper) {
        console.log("Test2 receiving event");
    }
})

Event pvStateControlEvt
 
<aura:event type="APPLICATION" description="My event" >
        <aura:attribute name="myAttribute" type="String"/>
</aura:event>

 
Amit GoyalAmit Goyal
Hi Jason, I am facing the same issue. do u have some solution for this?
Nitin Panchal 19Nitin Panchal 19
@Jason Sippie have find the solution for issue. I am facing the same issue. Event handler in notified twice on event fire
bryan.gilbertbryan.gilbert
Yes, I see this same problem and it indicates that SF is creating new components each time we click on a record in the list view. Performance degrades in my situation because the event handlers do a lot of work and in a short time there can be a 100 of them all doing the same.  Memory is likely to run out too.  I've posted a question to https://salesforce.stackexchange.com/questions/223806/application-event-fired-multiple-times-application-will-run-out-of-memory