Bug Tracker

Modify

Ticket #10077 (closed bug: invalid)

Opened 22 months ago

Last modified 20 months ago

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

Reported by: rgavel@… Owned by: rgavel@…
Priority: undecided Milestone:
Component: event Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

Description

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

comment:1 Changed 22 months ago by rwaldron

  • Owner set to rgavel@…
  • Status changed from new to pending
  • Component changed from unfiled to event
  • Milestone changed from None to 1.6.3

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 22 months ago by rgavel@…

  • Status changed from pending to new

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
		jQuery.bindReady();

		// 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 22 months ago by addyosmani

  • Status changed from new to pending

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 follow-up: ↓ 6 Changed 22 months ago by dmethvin

  • Milestone 1.6.3 deleted

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 22 months ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

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 20 months 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.