#7247 closed bug (fixed)
function bound to ready event fires twice on 1.4.3
Reported by: | dustymugs | Owned by: | gf3 |
---|---|---|---|
Priority: | blocker | Milestone: | 1.4.4 |
Component: | core | Version: | 1.4.3 |
Keywords: | regression | Cc: | |
Blocked by: | Blocking: |
Description (last modified by )
I'm currently using Firefox 3.6.10 and Opera 10.60 on Slackware Linux 12.1.
In jQuery 1.4.2, a function bound to the document ready event fires once. The same is not true in 1.4.3. A simple test case can be found at:
[
For the test case above, the jquery version number should appear only once. It shows up twice for 1.4.3.
Change History (17)
comment:1 Changed 12 years ago by
Component: | unfiled → core |
---|---|
Keywords: | regression added |
Milestone: | 1.5 → 1.4.4 |
Priority: | undecided → blocker |
Status: | new → open |
comment:2 Changed 12 years ago by
$(document).bind( 'ready', fn )
not only double-fires, but bound handlers also execute out-of-order. Note that $(document).ready( fn )
and $( fn )
seem fine.
comment:3 Changed 12 years ago by
Confirmed in Opera 10.63, FF 4.04b, FF 3.6.10, Chrome and IE6 on Windows XP.
All show the same behavior. "ready bind bind" for snovers test case and the same order cowboy documented on his test-case
comment:4 Changed 12 years ago by
I use $(function(){}); in ie 7.0, the ready event is also double fires.
But sometimes OK, sometimes fail...the only way is back to v1.4.2....
comment:5 Changed 12 years ago by
Owner: | set to gf3 |
---|---|
Status: | open → assigned |
comment:6 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Make sure that the ready event doesn't double-fire when .bind(ready) is used. Fixes #7247.
Changeset: 3df41db0369cfaf0fc229c633eb87f222ad49357
comment:7 Changed 12 years ago by
Will deal with the out-of-order events over here: #7279 (that was an issue in 1.4.2 and earlier as well - it will require a lot more work, should go into 1.5, probably).
comment:9 Changed 12 years ago by
I've tried apply the changes from the changeset to my code, but the event still fires twice.
In fact, before applying it it would seem to sometimes fire twice, and afterwards it is always firing twice.
I have tried both $(document).ready and $(document).bind('ready'
Is there anything I am doing wrong?
comment:10 Changed 12 years ago by
Description: | modified (diff) |
---|
Can you test this with http://code.jquery.com/jquery-git.js
comment:11 Changed 12 years ago by
OK, I tried with that, and it still happened.
But then I played around a bit more, and it seems the problem was I was using an alert to check if it fired twice, and I kept getting two alerts. I switched to using console.log and only one message was logged. I combined both, so had an alert and a log in the handler, and got two alerts and two logs to the console.
So, it seems it is the alert that is causing the problem for me. I guess because it holds up execution of the handler, so the unbind doesn't happen until the alert is called.
I'm new to jQuery, so don't know enough of the inner workings to know if there is a clever workaround for this. Although, I've also only just discovered console.log, and so will probably be using that instead of alert from now on anyway, so may not encounter the problem again.
comment:12 follow-up: 13 Changed 12 years ago by
I can confirm the bug still remains in IE 6-9 (in IE8 always) Sample: http://pastebin.com/sa2Ays8M
comment:13 Changed 12 years ago by
Replying to nAS:
I can confirm the bug still remains in IE 6-9 (in IE8 always) Sample: http://pastebin.com/sa2Ays8M
i confirm bug with jquery 1.4.4rc2
comment:16 Changed 12 years ago by
The bug seems to happen only when alert()
is used in the callback. When logging is used it gets executed only once - exactly as stated above.
Furthermore, it does not matter whether we use $(function () {})
or $(document).ready(function (){})
.
comment:17 Changed 12 years ago by
I seem to be having the problem even if I do not use alert. But it does not happen on all instances of $(document).ready and $(function().
improved test case