[SalesForce] Invalid component tried calling function [getElement], markup://aura:html [132:c]

I am using the $A.createComponents() method to dynamically insert different components into the body of my Lightning application. I am executing this function using a custom Lightning event where I am passing the $A.createComponent() method an attribute which is the name of the component that I want to render. On a button click event, the custom Lightning event fires, passing the component name to the $A.createComponents() method for dynamic rendering.

Periodically, I am getting the following error logged to my window once the component is dynamically rendered to the screen.

Invalid component tried calling function [getElement], markup://aura:html [132:c]

Even though this system error logs to the window, the component still renders. I'm not sure what is causing this error. It would help me troubleshoot it to have an idea of exactly what it means?

Could anyone provide some insight on this one?

Thanks!

Best Answer

Two possibilities here, you're trying to rerender an html element which is invalid. If this is the case, it's a framework bug since we should detect that.

The more likely scenario, you're calling .getElement() on a component, and that component has since been unrendered and destroyed.

Due to the asynchronous nature of the framework this just happens sometimes. You should gate the logic based on a isValid check.

if(cmp.isValid()) { 
 var element = cmp.getElement();
}