Opened 8 years ago

Closed 7 years ago

#14970 closed defect (wontfix)

loader fails to load modules that map to the same URL correctly

Reported by: Rawld Gill Owned by: Rawld Gill
Priority: low Milestone: 1.8
Component: Loader Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:

Description

(reported by neonstalwart)

script tag in page

require({
baseUrl: './',
paths: {
multiple: 'multiple',
duplicate: 'multiple'
}
}, ['multiple', 'duplicate'], function (multiple, duplicate) {
multiple.multi = true;
console.log('multiple', multiple.multi);
console.log('duplicate', duplicate.multi);
});

multiple.js

console.log('loaded');
define(function (require, exports, module) {
console.log('defined', module.id);
return {};
});

i'd expect to see the following in the console:

loaded
defined multiple
defined duplicate
multiple true
duplicate undefined

the loader appears to not do this

see also: http://groups.google.com/group/amd-implement/browse_thread/thread/138b9ef50f458a67

Attachments (2)

multiple.html (500 bytes) - added by ben hockey 8 years ago.
test page
multiple.js (120 bytes) - added by ben hockey 8 years ago.
test module

Download all attachments as: .zip

Change History (5)

comment:1 Changed 8 years ago by Rawld Gill

Milestone: tbd1.8
Priority: undecidedlow
Status: newassigned

Changed 8 years ago by ben hockey

Attachment: multiple.html added

test page

Changed 8 years ago by ben hockey

Attachment: multiple.js added

test module

comment:2 Changed 8 years ago by Rawld Gill

@neonstalwart: Why wouldn't you expect multiple.js to be evaluated twice, thereby causing two console.log("loaded') calls?

comment:3 Changed 7 years ago by Rawld Gill

Resolution: wontfix
Status: assignedclosed

Looking into this a bit further, it seems like the precise behavior is undefined according to the AMD spec. Further, the loader is behaving consistent with https://github.com/jrburke/requirejs/blob/master/tests/urlfetch/urlfetch.html.

For my taste, I don't like this behavior. If two different modules are mapped to the same resource, then the best practice is for that resource should have a single anon define. But what if it doesn't as per the test above?

fwiw, here is how to rewrite the test to get the "correct" effect:

<html>
	<head>
		<script type="text/javascript" src="../../../dojo.js" data-dojo-config="async:1"></script>
		<script type="text/javascript">
			require({
				baseUrl: './',
				paths: {
					multiple: 'multiple',
					duplicate: 'multiple'
				},
				packages: [{
					name:"p1",
					location:".",
				},{
					name:"p2",
					location:".",
					paths:{"p2/duplicate":"multiple"}
				}]
			}, ['p1/multiple', 'p2/duplicate'], function (multiple, duplicate) {
				multiple.multi = true;
				console.log('multiple', multiple.multi);
				console.log('duplicate', duplicate.multi);
			});
		</script>
	</head>
</html>

Owing to the lack of a standard for this dusty corner, I'm not going to address this in 1.x.

Note: See TracTickets for help on using tickets.