+ Start a Discussion
AK-2AK-2 

afterRender event causes an error

I am trying to use the afterRender event in a custom component (below is the component markup, js handler and the error I am seeing). I have taken out all the code in the handler but I still can't get around the error. I also don't know what parameter I should be setting for value in the component markup for the handler. The documentation around afterRender is pretty sparse so wanted to see if someone in the group could help. If I remove the afterRender handler, the component shows without error.
 
Thank you.
 
<!-- COMPONENT MARKUP -->
<aura:handler name="afterRender" action="{!c.afterRender}" value="{!this}"/>
 
//js controller afterRender
afterRender: function (component, helper) {
                       
        this.superAfterRender();           
       
    }

----- ERROR MESSAGE -----
Uncaught Error in $A.getCallback() [Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details.
Action failed: forceChatter:lightningComponent$controller$doInit [Cannot read property 'b' of undefined]]
Aaron Bailey 5Aaron Bailey 5
I've got the same issue with the exact same code. Only difference is my error complains about "Cannot read property 'g' of undefined".
Chiragkumar Patel 9Chiragkumar Patel 9
I am facing exact same Error , "Cannot read property 'g' of undefined". Have you find any fix ? or other way apart from using the Init & Setting definite Timeout ?
Raghav Khaitan 14Raghav Khaitan 14
Were you guys able to solve it? Im getting error that [e is null]
Aaron Bailey 5Aaron Bailey 5
Here's a nice simple example of using afterRender. Documentation on this is conflicting and confusing.

Application (for testing purposes)
<aura:application >
    <c:MyTestCmp />
</aura:application>
Component
<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
Controller (client-side)
({
	doInit : function(component, event, helper) {
		alert("Init Fired!")
	}
})
Helper (not used, only posted for sake of transparency)
({
	helperMethod : function() {
		
	}
})
Renderer
({
    afterRender : function(component, helper) {
        this.superAfterRender();
        
        alert("After Render Fired!");
    }
})
Test Example Screenshot
Example Screenshot

This took a lot of experimentation, so I hope it helps someone else out there.


 
Aaron Bailey 5Aaron Bailey 5
Here's a better screenshot
Example Screenshot