Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18826 closed defect (fixed)

dojo/parser confused by Node.rootNode

Reported by: Jeremiah Orr Owned by: bill
Priority: undecided Milestone: 1.8.12
Component: Parser Version: 1.11.1
Keywords: Cc:
Blocked By: Blocking:

Description

Support for Node.rootNode recently showed up in Chrome Canary (I'm on version 51.0.2699.0). This confuses dojo/parser.parse(), as it thinks that if the first argument has a rootNode property, it must be the options hash instead of a DOM node. The problem code is here: https://github.com/dojo/dojo/blob/master/parser.js#L873-L875

Now that it thinks rootNode is actually an options object, it looks to arguments[0].rootNode for where to begin parsing (instead of just arguments[0]). Since Node.rootNode returns the document root, it parses the entire document.

To see this in action, check out http://codepen.io/orr94/pen/EKbKeM in both Chrome and Canary. In Chrome, you'll see that only the first input element is parsed and turned into a Dijit widget, as expected. In the current version of Canary, you'll see that both inputs are parsed and turned into widgets.

Change History (8)

comment:1 Changed 4 years ago by bill

Component: GeneralParser
Owner: set to bill
Status: newassigned

Good catch. I guess we could reverse the test, and do something like:

if(typeof rootNode != "string && !("nodeType" in rootNode)){
    // caller omitted the rootNode parameter, so rootNode is actually the options hash (or it's undefined)
    options = rootNode;
    rootNode = options.rootNode;
}
var root = rootNode ? dom.byId(rootNode) : dwindow.body();

comment:2 Changed 4 years ago by Jeremiah Orr

With a tweak, that worked for me in Canary:

if(rootNode && typeof rootNode != "string" && !("nodeType" in rootNode)){
    // caller omitted the rootNode parameter, so rootNode is actually the options hash (or it's undefined)
    options = rootNode;
    rootNode = options.rootNode;
}
var root = rootNode ? dom.byId(rootNode) : dwindow.body();

This accounts for parser() being called with no args (parse the entire document with no options).

comment:3 Changed 4 years ago by bill

Milestone: tbd1.8.12

Great, makes sense. That passes the regression tests too. I'll check it in for 1.8.12, 1.9.9, 1.10.6 and 1.11.2.

comment:4 Changed 4 years ago by Bill Keese <bill@…>

Resolution: fixed
Status: assignedclosed

In 06203f3/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:5 Changed 4 years ago by Bill Keese <bill@…>

In 7374c3d7/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:6 Changed 4 years ago by Bill Keese <bill@…>

In 01bdb59/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:7 Changed 4 years ago by Bill Keese <bill@…>

In c0d62d0/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:8 Changed 4 years ago by Bill Keese <bill@…>

In c009c83/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.