Opened 7 years ago

Closed 7 years ago

#16958 closed defect (fixed)

Loader Exception in dojo-inject-api when insertPoint is removed

Reported by: chris2m Owned by: Rawld Gill
Priority: blocker Milestone: 1.9
Component: Loader Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

This ticket is related to http://bugs.dojotoolkit.org/changeset/30921/dojo%20bugs.dojotoolkit.org/ticket/15809

When injecting scripts into the dom dojo determines an insertPoint and a sibling node. The insertPoint typically is the head tag and the sibling is usually the first script node in the document. Under some circumstances the sibling node might be a temporarily inserted script tag (e.g. tracker code) which is removed at some point. Dojo currently relies on the sibling node being always present.
In case the sibling node is removed, all subsequent require("module") calls fail. The Patch used in #15809 is a workaround for the specific error situation described in that ticket, but does not provide a generic solution to the removal of the sibling nodes.

To fix this issue in my code I have inserted the following lines that check if the sibling is still present in the DOM. If not, insertPoint and sibling are re-assigned.

node.type = "text/javascript";
node.charset = "utf-8";
node.src = url;

// PATCH START
if (!((insertPoint.contains && insertPoint.contains(sibling)) || sibling.sourceIndex>=0)) {
    sibling = doc.getElementsByTagName("script")[0];
    insertPoint= sibling.parentNode;
}
// PATCH END
                                
insertPoint.insertBefore(node, sibling);

Best, Chris

Change History (5)

comment:1 Changed 7 years ago by bill

Component: GeneralLoader
Owner: set to Rawld Gill

comment:2 Changed 7 years ago by Rawld Gill

Resolution: fixed
Status: newclosed

In [31271]:

improved algorithm for determining insertion point of script injection; thanks chris2m; fixes #16958; !strict

comment:3 Changed 7 years ago by Rawld Gill

Milestone: tbd1.9
Priority: undecidedlow

I changed the algorithm to prefer the node sniffed as the last node that has either a data-dojo-config or djConfig attribute, or, failing that sniff, the last node sniffed with its src attribute containing "dojo.js".

In order for this to work, the sniff API must be turned on (it is by default).

This means that if you remove the sniffed node, you're still going to have a problem. In such cases, you could solve the problem by adding teh following node after any nodes that are going to be removed.

<script data-dojo-config=""></script>

and never removing it.

In 2.0, we'll just dispense with this whole insert point idea and insert into head...it's all to solve an ancient IE problem that probably no longer important.

comment:4 Changed 7 years ago by bill

Priority: lowblocker
Resolution: fixed
Status: closedreopened

[31271] breaks dijit/tests/registry.html (and probably other things) on IE8. It gets an exception loading the page.

comment:5 Changed 7 years ago by Rawld Gill

Resolution: fixed
Status: reopenedclosed

In [31272]:

make sure the sibling is computed; fixes #16958; !strict

Note: See TracTickets for help on using tickets.