Bug Tracker

Ticket #10687 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

jQuery calls the AMD define() global function too early

Reported by: john@… Owned by: timmywil
Priority: blocker Milestone: 1.7.1
Component: core Version: 1.7
Keywords: Cc:
Blocking: Blocked by:

Description

Hey guys!

Sorry I didn't discover this until after release. :(

jQuery shouldn't call the global AMD define() function until jQuery is fully defined. By "fully defined" I mean jQuery and all of its core helpers such as jQuery.Deferred, jQuery.Callbacks, etc.

Since jQuery doesn't expose these to AMD as individual modules, other AMD modules have to assume that they are defined when the jQuery object itself is defined.

See jsFiddle:  http://jsfiddle.net/unscriptable/GqfFM/

The easiest solution, imho, is to place the call to define() at the very end of the file.

Regards,

-- John "@unscriptable" Hann

Change History

comment:1 Changed 3 years ago by timmywil

#10686 is a duplicate of this ticket.

comment:2 Changed 3 years ago by timmywil

  • Priority changed from undecided to blocker
  • Status changed from new to open
  • Component changed from unfiled to core
  • Milestone changed from None to 1.7.1

Thanks John! We'll get a fix in for 1.7.1.

I'd like to have tests for as many amd loaders as possible for the next release, including curl.js and require.

comment:3 Changed 3 years ago by jrburke

I would like to discuss this on the amd-implement list first before a patch is applied. Normally an AMD loader needs to wait for the script to be defined for an anonymous module, so I think it may be useful to just standardize on that behavior even for named modules, more consistent execution behavior. I also thinks it makes it easier for libaries to implement calling AMD, less reworking of their codebase.

I will post back with a link to the amd-implement discussion once it gets set up.

comment:4 Changed 3 years ago by jrburke

Link to the amd-implement discussion I just started, for future reference:

 https://groups.google.com/group/amd-implement/browse_thread/thread/a2b113e38a42ea01

comment:5 Changed 3 years ago by jrburke

In the amd-implement thread, John makes a good case that an AMD loader should consider the module completely constructed once the factory function has finished. So I worked up the following patch for this ticket:

 https://github.com/jquery/jquery/pull/584

comment:6 Changed 3 years ago by jrburke

A new pull request was done for this ticket based on feedback from timmywil:

 https://github.com/jquery/jquery/pull/586

This one replaces #584.

comment:7 Changed 3 years ago by dmethvin

  • Owner set to timmywil
  • Status changed from open to assigned

comment:8 Changed 3 years ago by jrburke

  • Status changed from assigned to closed
  • Resolution set to fixed

Landing pull request 586. Create exports.js for exporting jQuery to window and AMD. Fixes #10687.

More Details:

Note: See TracTickets for help on using tickets.