Opened 6 years ago

Closed 6 years ago

#17547 closed defect (duplicate)

_Container: addChild index cannot be non sequential

Reported by: Jared Jurkiewicz Owned by:
Priority: undecided Milestone: tbd
Component: Dijit Version: 1.9.1
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Jared Jurkiewicz)

Before 1.9, _LayoutWidget.addChild would allow you to pass an index that didn't exist. For example someone calls someLayout.addChild(widget, 1); But there are no widgets in someLayout yet. This would still succeed and just insert it as the first child widget. In 1.9, it now throws an error:

var refNode = this.containerNode; if(insertIndex > 0){ Old-school way to get nth child; dojo.query would be easier but _Container was weened from dojo.query in #10087 to minimize download size. Not sure if that's still and issue with new smaller dojo/query. refNode = refNode.firstChild; while(insertIndex > 0){ if(refNode.nodeType == 1){ insertIndex--; } ERROR refNode is null

A simple fix for this is probably just adding a check to refNode before going into that loop. Example:

var refNode = this.containerNode; if(insertIndex > 0){

Old-school way to get nth child; dojo.query would be easier but _Container was weened from dojo.query in #10087 to minimize download size. Not sure if that's still and issue with new smaller dojo/query. refNode = refNode.firstChild; while(refNode && insertIndex > 0){

if(refNode.nodeType == 1){ insertIndex--; } refNode = refNode.nextSibling;

} if(refNode){

insertIndex = "before";

}else{

to support addChild(child, n-1) where there are n children (should add child at end) refNode = this.containerNode; insertIndex = "last";

}

}

Change History (2)

comment:1 Changed 6 years ago by Jared Jurkiewicz

Description: modified (diff)

comment:2 Changed 6 years ago by bill

Component: GeneralDijit
Resolution: duplicate
Status: newclosed
Summary: _Container.addChild regression_Container: addChild index cannot be non sequential

Duplicate of #16874.
It's natural to get exceptions when you call functions with illegal parameters. As I wrote in #17252 and #16874, passing an index to addChild() that's too high isn't supposed to work, nor was it ever documented to work. To me, it seems better to throw an exception, to let the user know that there's an error in their code.

Note: See TracTickets for help on using tickets.