Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#513 closed defect (fixed)

dojo.require assumes too easily that a module is already loaded

Reported by: ningu Owned by: James Burke
Priority: high Milestone:
Component: Core Version: 0.2
Keywords: Cc:
Blocked By: Blocking:


Try doing the following on a dojo with nothing additional baked in:

dojo.require("dojo.animation.Timer"); dojo.require("dojo.widget.ComboBox?"); dojo.require("dojo.widget.html.ComboBox?");

The result is a failure to load dojo.animation, which means that dojo.widget.html.ComboBox? will cause Javascript errors when you try to use it. This happens on line 652 of boostrap1.js:

var module = dojo.evalObjPath(modulename);

where an existing dojo.animation object is returned (because of Timer) and therefore, it is assumed that the whole package is loaded. But it is not!

I don't really know what the "right" way to fix this is, but it is sure to cause frequent bewilderment like it did to me today. :-)

Change History (7)

comment:1 Changed 15 years ago by bill

Same problem w/dojo.math. Here's a previous mail from Laurie:

There seems to be a problem with the package system. I suspect it'll cause breakage in a lot more places, but you can see the problem by loading test_Accordion.html and clicking one of the title bars. I get an error in the Firefox JS console telling me that dojo.math.bernstein is not a function.

The problem is that dojo.math is being dojo.require'd after dojo.math.curves. The dojo.require('dojo.math') call does nothing because the prior dojo.require('dojo.math.curves') has already created the dojo.math namespace, I think.

I've worked around the problem by calling dojo.require('dojo.math') before require'ing anything else, but as m8 pointed out on IRC, a bunch of other stuff is probably broken by this.

I can file a bug in Trac, but I thought I'd post first since I'm not sure what the right fix is... I haven't dug in too deeply, but maybe dojo.require() is checking for the existence of the namespace without checking the associated module has been loaded?

comment:2 Changed 15 years ago by bill

Version: 0.2

After some IRC discussion, proposed fix:

dojo.provides should update dojo.hostenv.loaded_modules_, and dojo.require should reference it

Note on terminology: a module is equivalent to a file (ie, something that can be dojo.required), and a namespace is equivalent to a java package.

comment:3 Changed 15 years ago by James Burke

Milestone: 0.3release0.4
Owner: changed from anonymous to James Burke
Status: newassigned

comment:4 Changed 15 years ago by James Burke

Notes for a fix: consider in dojo.hostenv.findModule() in loader.js returning false if it is not found in this.loaded_modules_[lmn]. See if this impacts xdomain loading, or some other case where the evalObjPath was helpful.

comment:5 Changed 15 years ago by James Burke

Also be sure to scrub for fixes. Check on the following thread to make sure there are no other cleanup items (looks like Bill got most of them):

Some Provide/Require? Questions

comment:6 Changed 15 years ago by James Burke

Resolution: fixed
Status: assignedclosed

Fixed in [5219]. I also made sure the comparisons on package names were case sensitive.

comment:7 Changed 14 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.