localRequirejs tries to load incorrect path

Help improve MediaMonkey 5 by testing the latest pre-release builds, and reporting bugs and feature requests.

Moderator: Gurus

TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

localRequirejs tries to load incorrect path

Post by TIV73 »

Hi,
I recently added a configuration screen to an extension, the (simplified) layout looks like this:

Code: Select all

myAddon/myAddon.js:

myAddon = {
  someFunction: function(){
	alert('some function')
  }
}


myAddon/info.json:

{
	"config": "config.js",
	...
}


myAddon/config.js:

localRequirejs('myAddon')

window.configInfo = {
	load: function(panel, addon){
        panel.innerHTML = [some html code];
		myAddon.someFunction();
	}
}
If I now go to Toos > Extensions and open the configuration menu for the extension, I get a file not found exception for myAddon/myAddon.js, because localRequirejs points to the wrong folder.
Checking the function, it looks like localRequirejs internally calls requirejs with the __scriptName parameter (among others).

I updated the load function to do the following:

Code: Select all

load: function(panel, addon){
	console.log("__scriptName:"+ __scriptName)
	console.log("addon:")
	console.log(addon.title)
	console.log(addon.ext_id)
	console.log(addon.configFile)
}
Which gave me the following output:

Image

__scriptName returns a completely different addon. When calling __scriptName from other locations, e.g. the directly in the script file, it works fine. It seems like this only happens when the variable is accessed from a context that's not the main window.

Now, I'm not sure if I'm even supposed to use localRequirejs instead of requirejs with an explicit path here, the behavior just seems weird.


Update:
I did some more testing and found the following
  • If I remove all scripts but the one with the config.js file everything works fine. Which can probably be expected because there is no other extension that could provide a wrong path.
  • The exception doesn't occur if there are only few extensions, but it happens eventually if I gradually add more extensions.
  • __scriptName will always provide the same (wrong) addon if the same addons are loaded, but it's not related to one specific addon e.g. if __scriptName returns extension A once, it will always return that specific extension. If I delete extension A, __scriptName will return another (seemingly) random extension - but it will always return that same other extension. What I'm trying to say is that the loaded extension is, while incorrect, still deterministic, not completely random.
  • I made sure to also test this for addons that are included by default, not the ones I wrote. The result remains the same.
PetrCBR
Posts: 1763
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech
Contact:

Re: localRequirejs tries to load incorrect path

Post by PetrCBR »

I think it's problem with opening configuration of the addon (__scriptName wasn't set properly) ... will check it out.

EDIT: will be fixed in next build
How to make a debuglog - step 4b: viewtopic.php?f=30&t=86643
Post Reply