Skip to main content

Bug Tracker

Side navigation

#5261 closed bug (fixed)

Opened September 16, 2009 10:10PM UTC

Closed December 09, 2009 09:45PM UTC

ready functions can be called out of order

Reported by: dil Owned by: brandon
Priority: major Milestone: 1.4
Component: event Version: 1.4a1
Keywords: patch Cc:
Blocked by: Blocking:

A ready function added while inside another ready function will get called immediately rather than being added to the readyList. This can make the calls appear to be out-of-order since the rest of the readyList functions are not completed before the new function is executed. This behavior is caused by the ready function setting isReady before running the readyList functions but the ready(fn) call does not check if the ready functions are currently being executed to decide if a new function should be run immediately or added to the readyList. (The 1.3.3 $.each() to while loop patch from [6323] as addressed in #5209 is also required for this to work at all.)

Testcase showing secondary function running immediately rather than waiting for current ready function to complete. Prints "A2 A1" rather than "A1 A2".


Testcase showing secondary function running immediately rather than waiting for current and queued ready functions to complete. Prints "B3 B1 B2" rather than "B1 B2 B3".


Patch for ready(fn) from latest SVN code:

--- event.js    (revision 6581)
+++ event.js    (working copy)
@@ -704,8 +704,8 @@
                // Attach the listeners
-               // If the DOM is already ready
-               if ( jQuery.isReady ) {
+               // If the DOM is ready and the readyList has been processed
+               if ( jQuery.isReady && !jQuery.readyList ) {
                        // Execute the function immediately
               document, jQuery );
Attachments (0)
Change History (1)

Changed December 09, 2009 09:45PM UTC by john comment:1

resolution: → fixed
status: newclosed