Skip to main content

Bug Tracker

Side navigation

#7273 closed bug (wontfix)

Opened October 21, 2010 07:47PM UTC

Closed October 21, 2010 07:58PM UTC

Last modified March 14, 2012 01:24AM UTC

Ready event fired multiple times if an unhandled exception occurs

Reported by: Michael Warning Owned by:
Priority: undecided Milestone: 1.5
Component: core Version: 1.4.3
Keywords: ready exception error-handling Cc:
Blocked by: Blocking:
Description

If a ready handler causes an unhandled exception then the ready list will be run twice. I'm testing with 1.4.3 in both Firefox and Safari. e.g.:

jQuery(document).ready(function()

{

alert('in ready');

window.frooble();

});

This appears to happen because two callbacks are registered via addEventListener ("DOMContentLoaded" and "load"). The DOMContentLoaded handler cleans up after itself but it doesn't cleanup the load handler as well.

Alternatively, the ready list is null'd out after it is processed instead of making a copy, nulling the original, and only then walking the list.

Attachments (0)
Change History (10)

Changed October 21, 2010 07:58PM UTC by SlexAxton comment:1

component: unfiledcore
keywords: → ready exception error-handling
resolution: → wontfix
status: newclosed

I don't think jQuery has any history of trying to act nicely when you throw unhandled exceptions. If you might throw an exception, wrap it in a try catch.

Changed October 27, 2010 01:02PM UTC by hwaara@gmail.com comment:2

I got bitten by this bug as well! Took hours to figure out the cause that $(document).ready was firing twice. Are you sure this is wontfix?

Changed October 28, 2010 11:51AM UTC by anonymous comment:3

We have also been bitten by this! We tracked it down to a 3rd party plugin throwing an exception. It seems unreasonable for us to have to patch each 3rd party plugin to make them all catch exceptions.

I'm not sure if wontfix is really the right approach here.

Changed November 05, 2010 11:31PM UTC by nornagon@nornagon.net comment:4

Just wasted an hour and a half stepping through jQuery trying to work out what was going wrong, and this was it. The bug doesn't occur in 1.3.2.

This is a real regression.

Changed November 05, 2010 11:47PM UTC by rwaldron comment:5

Replying to [comment:4 nornagon@…]:

Just wasted an hour and a half stepping through jQuery trying to work out what was going wrong, and this was it. The bug doesn't occur in 1.3.2. This is a real regression.

Test in 1.4.4rc2

k thanks.

Changed November 07, 2010 03:28AM UTC by Nicolas Cordin <nicolas.cordin@gmail.com> comment:6

Hi, this is not fix in 1.4.4rc2.

I also think it's a important regression, we have really strange results when we are testing/coding applications.

I lost hours to understand what happend and finding this bug.

Changed November 07, 2010 03:31AM UTC by rwaldron comment:7

Confirmed. But still, I don't think you should hold jQuery responsible for your unhandled exceptions.

http://jsfiddle.net/rwaldron/S2D5b/1/

Changed November 08, 2010 03:48PM UTC by buddywilliams@gmail.com comment:8

I disagree. While jQuery should not "be responsible" for the unhandled exception, it shouldn't as a side-effect create a new exception. This is exactly what is happening here. This means that I cannot trust .ready() because it may actually execute more than once...!?

This is a very undesirable bug especially when considering 3rd party code which you have little or no control over.

I agree that many problems should just be problems until fixed by users but this is a side-effect problem which is dangerous and greatly reduces trust in a much relied on and needed method from jQuery.

Changed November 17, 2010 08:24PM UTC by localinfidelity@hotmail.com comment:9

I concur with buddywilliams that while jQuery shouldn't cause further problems due to already existing issues. Just ran into this myself and debugged for about an hour until I stumbled across this post.

Changed November 17, 2010 08:27PM UTC by localinfidelity@hotmail.com comment:10

Nevermind, it appears to be fixed in 1.4.4. Why does the jQuery front page say the latest release is 1.4.3 =/