I have a Nav component which contains the following:
<aura:renderIf isTrue="{!v.showAllProducts}">
<c:showAllProductsCmp/>
<aura:set attribute="else">
<c:showSelectedProductsCmp/>
<aura:set>
<aura:renderIf>
On a button press, showAllProducts
changes from false -> true, and true -> false.
What this does is allow a user to see all products and select them (this is done in the showAllProductsCmp
component. The component simply uses <aura:iteration>
to render all product objects.)
and then switch to see only the selected products with the option to unselect them (in the showSelectedProductsCmp
component).
I can add and remove any/all products, and my code works as intended -- as long as there is at least one product remaining. For example, I can add 4 products, remove 3, and it works perfectly.
As soon as I remove the last product in the showSelectedProductsCmp
and then try to switch back over to the showAllProductsCmp
, the app crashes and I get a javascript error:
Uncaught TypeError: Cannot read property 'childNodes' of null
aura_proddebug.js:8364
This line is part of the Lightning framework. Specifically it is:
nextSibling = target.childNodes[calculatedPosition];
So the target
variable is null and it crashes.
If I remove renderIf
and set attribute="else"
components and ALWAYS render my two custom components, everything works as it should and there are no errors -- even if I remove all products.
So I don't believe that there is anything wrong with my code, though I would be happy to be corrected :)
PS: This doesn't happen on all renderIf statements: I have quite a few of them in my code and all of them work except for this one. Which means that this is hard to reproduce, sadly.
[Edit] I guess I should note that this nav component comes after quite a few other renderIf components, so maybe Lightning struggles with more than a couple renderIf components. Another person has a similar problem to mine, and s/he also has multiple renderIf statements before the one that finally breaks. developer.salesforce.com
[Edit2] Here is how you can reproduce the error (I'm pretty sure): Create a new Lightning application and copy the following code (which contains a lot of renderIfs)
[Edit3] The previous example had an error that was my fault. I've made a new example that hopefully doesn't have an error that is my fault. :)
<aura:application >
<aura:attribute name="isEmptyArray" type="Boolean" default="false"/>
<aura:attribute name="testingArray" type="Opportunity[]"/>
<button onclick="{!c.fillArray}">Fill array</button>
<button onclick="{!c.emptyArray}">Empty Array</button>
<div>
<aura:renderIf isTrue="{!v.testingArray.length > 0}">
<aura:iteration items="{!v.testingArray}" var="opp">
{!opp.name} <br/>
</aura:iteration>
<aura:set attribute="else">
Array empty
</aura:set>
</aura:renderIf>
</div>
</aura:application>
And then copy the following code into the application controller:
({
fillArray:function(component,event,helper) {
var tempArray = [{'sobjectType': 'Opportunity', 'name':'One'},{'sobjectType': 'Opportunity', 'name':'Two'}];
component.set("v.testingArray", tempArray);
},
emptyArray:function(component,event,helper) {
var emptyArray = [];
component.set("v.testingArray", emptyArray);
}
})
Click the "fill array" button, then the "empty array" button, then the "fill array" button again. Receive the error.
target
is being defined possibly?var target = referenceNode || component.$_marker$.parentNode;
So it's still part of the Lightning framework.