Side navigation
#9678 closed bug (fixed)
Opened June 27, 2011 03:10PM UTC
Closed August 25, 2011 07:43PM UTC
Last modified March 08, 2012 11:48PM UTC
setInterval cleared by animation
Reported by: | kertesz@auroscience.hu | Owned by: | timmywil |
---|---|---|---|
Priority: | low | Milestone: | 1.6.3 |
Component: | effects | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In Google Chrome setInterval callback will not execute when preceded by jQuery animation, see code below.
- Tested with Chrome 11.0.696.60
- Only when loaded into new browser tab! Will run as expected after page refresh.
- No trouble in IE8
- No trouble with jQuery 1.5.2
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script> $(document).ready( function () { $('#box').slideUp(); } ); function tick() { $('#ticks').append('+'); } setInterval(tick, 1000); </script> </head> <body> <div id="box">XXX</div> <div id="ticks"></div> </body> </html>
My guess is that interval timer ID = 1 is affected by the jQuery animation code.
Attachments (0)
Change History (14)
Changed June 27, 2011 03:22PM UTC by comment:1
component: | unfiled → effects |
---|---|
priority: | undecided → low |
resolution: | → worksforme |
status: | new → closed |
Changed June 27, 2011 03:31PM UTC by comment:2
Sorry I did not tell that you cannot reproduce this is jsFiddle.
Please try code on its own.
Changed June 27, 2011 08:14PM UTC by comment:3
OK, I got it.
Look at the 1.6.1 source, within jQuery.custom() we have
8356 timerId = 1;
Now if we do have requestAnimationFrame, as is the case with Chrome,
raf is passed as callback to requestAnimationFrame,
so raf will execute jQuery.fx.tick which eventually calls jQuery.fx.stop,
which has
8480 clearInterval( timerId );
thus killing my interval timer.
But why do we have timerId = 1 in the first place?
Changed June 28, 2011 03:17PM UTC by comment:4
Hi there, I just wanted to comment on this to mention that I've just hit this bug myself (Chrome 12.0.742.100, jQuery 1.6.1) and came to the exact same conclusion about the explicit call to set timerId to 1 and then calling clearInterval(timerId) even if the animation wasn't kicked off with setInterval.
I worked around it by creating a dummy setInterval first so that my real update function has an ID that's >= 2.
When reproducing this it's critical to start in a fresh browser tab (as mentioned in the original bug) because after a refresh your first setInterval will have an ID that isn't 1.
Changed June 28, 2011 03:27PM UTC by comment:5
resolution: | worksforme |
---|---|
status: | closed → reopened |
timerId was set to 1 because it's a short way to set a truthy value. The number 1 is not significant, so if it is conflicting with a timer id, we can set it to some other truthy value.
Something to watch timer ids:
Changed June 28, 2011 03:49PM UTC by comment:6
owner: | → timmywil |
---|---|
status: | reopened → assigned |
Confirmed
Changed June 28, 2011 04:50PM UTC by comment:7
resolution: | → fixed |
---|---|
status: | assigned → closed |
Set timerId to true instead of a number so that intervals set to 1 are not accidentally cleared when stopped. Fixes #9678.
- Adding a working test case would not be possible in this case, but all tests pass.
Changeset: ab1504f14f56944a5a6297c68b323f0af01d5be8
Changed June 28, 2011 04:52PM UTC by comment:8
milestone: | 1.next → 1.6.2 |
---|
Changed July 04, 2011 10:47AM UTC by comment:9
This bug doesn't seem to be fixed in 1.6.2. I just tried the test case in the original report (updating the script tag to pull in 1.6.2) and it still fails.
Changed July 04, 2011 02:19PM UTC by comment:10
The only way that would be possible would be if clearInterval( true ) cleared the timer id of 1, which I'm surprised to learn that it does. http://jsfiddle.net/timmywil/ePVAZ/1/show/
However, I am only able to reproduce this when jQuery is not included on the page.
Changed July 19, 2011 08:38AM UTC by comment:11
I think this ticket needs to be reopened given the previous comment. I'm seeing the same results with the jsfiddle link provided.
It seems dangerous to call clearInterval on a value unless we know it's a valid timerId. What about wrapping the call to clearInterval in an if statement:
if (typeof timerId === 'number') {
clearInterval(timerId);
}
timerId = null;
Changed July 19, 2011 01:21PM UTC by comment:12
resolution: | fixed |
---|---|
status: | closed → reopened |
You're right
Changed July 19, 2011 01:26PM UTC by comment:13
milestone: | 1.6.2 → 1.next |
---|---|
status: | reopened → open |
For 1.6.3
Changed August 25, 2011 07:43PM UTC by comment:14
milestone: | 1.next → 1.6.3 |
---|---|
resolution: | → fixed |
status: | open → closed |
This is fixed for 1.6.3.
Works for me in latest Chrome with jQuery Edge: http://jsfiddle.net/rwaldron/7SwMx/