Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10077 closed bug (invalid)

Ready doesn't work when multiple calls made after readState = complete

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone:
Component: event Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


I am using Internet Explorer 9 and have multiple included javascript files that contain there own $(function () { ... } calls. However, they are not getting called. In debugging into ready, I have found that at the time of invoking bindReady, document.readyState is "complete". From my reading of bindReady, in this case, the first run will invoke the internal ready function after 1 sec (by which time the external ready call will have added the callback function to readyList). However, a subsquent call to bindReady will consider itself bound and never schedule the internal ready function again.

Change History (6)

comment:1 Changed 11 years ago by Rick Waldron

Component: unfiledevent
Milestone: None1.6.3
Owner: set to [email protected]
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 11 years ago by [email protected]

Status: pendingnew

FYI, I will try and use jsFiddle to provide test case. However, I did find a fix in moving the readyState check from bindReady to the ready after the callback function is added to the readyList.Done collection:

	ready: function( fn ) {
		// Attach the listeners

		// Add the callback
		readyList.done( fn );

		// Catch cases where $(document).ready() is called after the
		// browser event has already occurred.
		if (document.readyState === "complete") {
		    // Handle it asynchronously to allow scripts the opportunity to delay ready
		    return setTimeout(jQuery.ready, 1);

		return this;

comment:3 Changed 11 years ago by addyosmani

Status: newpending

Thanks for the proposed fix. Ideally, patches are best submitted in the form of pull-requests with tests attached so that the rest of the team can verify a) the patch is worth using and b) it doesn't have any negative side-effects upon existing functionality. If you could post a test case to jsFiddle shortly we can look into this further.

comment:4 Changed 11 years ago by dmethvin

Milestone: 1.6.3

We definitely need a test case for this. If you look at bindReady() it already has a check for readyState that should have handled this case.

comment:5 Changed 11 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:6 in reply to:  4 Changed 11 years ago by anonymous

Replying to dmethvin:

We definitely need a test case for this. If you look at bindReady() it already has a check for readyState that should have handled this case.

I know I still need to provide a test case for this. Lost track because I hacked our local copy of jQuery.js to work. The issue with bindReady is this: The first call to ready (and therefore bindReady) will cause readyList to be instantiated. Any subsequent calls will short-circuit return from bindReady since the readyList is non-null.

Note: See TracTickets for help on using tickets.