Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#11278 closed defect (fixed)

dojox.mobile.parser reparses the page every time _loadUri completes, breaking widgets

Reported by: Shane O'Sullivan Owned by: Jared Jurkiewicz
Priority: high Milestone: 1.5
Component: DojoX Mobile Version: 1.5.0b3
Keywords: Cc: James Burke, phiggins, bill, wildbill
Blocked By: Blocking:

Description (last modified by Jared Jurkiewicz)

dojox.mobile.parser contains the following code, which is always executed.

dojo._loaders.unshift(function(){

dojox.mobile.parser.parse();

});

When used with the dojox.mobile.app code, each time a new XHR completes, the parse() function is invoked on the entire page. The breaks when it encounters an already instantiated widget, saying that the widget is already loaded.

To those CC'ed, do you have any idea why the lightwieght parser is getting repeatedly called on _loadURI?

Why is this necessary? Can dojo.addOnLoad() not be used so that it is only invoked once? This breaks any mobile app that has more than one templated view, and would be good to get fixed for 1.5

Change History (13)

comment:1 Changed 9 years ago by Jared Jurkiewicz

Cc: James Burke phiggins bill wildbill added
Description: modified (diff)

The original author, Yoshiroh Kamiyama, denoted this is how the other parser works, and should be cleared after exec. And he's right. Looking in dojo.parser:

(function(){

var parseRunner = function(){

if(dojo.config.parseOnLoad){

dojo.parser.parse();

}

};

FIXME: need to clobber cross-dependency!! if(dojo.exists("dijit.wai.onload") && (dijit.wai.onload === dojo._loaders[0])){

dojo._loaders.splice(1, 0, parseRunner);

}else{

dojo._loaders.unshift(parseRunner);

}

})();

So I'm not sure why it is running either.

comment:2 Changed 9 years ago by Jared Jurkiewicz

Actually, I have a theory. The template code is trying to call the parser on a template ... and it's passing a params object as the first parameter, not the root node. Or something like that, maybe. I'm not sure. Can you try the following and see if ti makes a difference?

@@ -57,6 +57,9 @@
 		//		The root node in the document to parse from
 		if(!rootNode){
 			rootNode = dojo.body();
+		}else if(!defaultParams && rootNode.rootNode){
+			// Case where 'rootNode' is really a params object.
+			rootNode = rootNode.rootNode;
 		}
 		var nodes = rootNode.getElementsByTagName("*");
 		var list = [];

comment:3 Changed 9 years ago by Shane O'Sullivan

The template code is definitely passing in a root node, and that node is parsed successfully. A second parse is executed by the parser's callback function I described earlier

However, I'll try this solution when I get home to see if it helps. The solution I've found is to just use dojo.addOnLoad() in the parser, rather than directly accessing the dojo._loaders, but perhaps that's not ideal.

comment:4 Changed 9 years ago by Shane O'Sullivan

(In [22314]) Refs #11278 Fixes parsing bug in dojox.mobile.parser where it will incorrectly reparse the page when templates are loaded !strict

comment:5 Changed 9 years ago by Shane O'Sullivan

Resolution: fixed
Status: newclosed

Added the change suggested by jaredj, fixes the issue, closing

comment:6 Changed 9 years ago by Shane O'Sullivan

Resolution: fixed
Status: closedreopened

This is still an issue. I am going to change the code to use dojo.addOnLoad, which seems to function just the same, but only runs once.

comment:7 Changed 9 years ago by Shane O'Sullivan

(In [22323]) Refs #11278 Fixes the issue where the parser is executed whenever _loadUri completes. This fix ensures that it is only run once, at page load time. !strict

comment:8 Changed 9 years ago by Shane O'Sullivan

Resolution: fixed
Status: reopenedclosed

comment:9 Changed 9 years ago by bill

FYI, the weird dojo._loaders.unshift call, rather than a simple dojo.addOnLoad call, is so the code to detect whether the machine is in high-contrast mode will run before the parser does.

Presumably that's not an issue for mobile.

comment:10 Changed 9 years ago by Shane O'Sullivan

Resolution: fixed
Status: closedreopened

This is still an issue. dojo.addOnload should not be used, as it does not ensure that the parsing is run before all other onload listeners.

comment:11 Changed 9 years ago by Shane O'Sullivan

(In [22355]) Refs #11278 Ensures that the parse is only executed if parseOnLoad is true. Also ensures that the parse is run before other onload listeners !strict

comment:12 Changed 9 years ago by Shane O'Sullivan

Resolution: fixed
Status: reopenedclosed

comment:13 Changed 9 years ago by bill

Component: DojoxDojoX Mobile
Note: See TracTickets for help on using tickets.