Skip to main content

Bug Tracker

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: Owned by: timmywil
Priority: low Milestone: 1.6.3
Component: effects Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

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>
<script src=""></script>

$(document).ready( function () {
} );

function tick() {

setInterval(tick, 1000);


   <div id="box">XXX</div>
   <div id="ticks"></div>

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 rwaldron comment:1

component: unfiledeffects
priority: undecidedlow
resolution: → worksforme
status: newclosed

Works for me in latest Chrome with jQuery Edge:

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 anonymous 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 timmywil comment:5

resolution: worksforme
status: closedreopened

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 timmywil comment:6

owner: → timmywil
status: reopenedassigned


Changed June 28, 2011 04:50PM UTC by timmywil comment:7

resolution: → fixed
status: assignedclosed

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 timmywil comment:8

milestone: 1.next1.6.2

Changed July 04, 2011 10:47AM UTC by supersi2000 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 timmywil 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.

However, I am only able to reproduce this when jQuery is not included on the page.

Changed July 19, 2011 08:38AM UTC by anonymous 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') {



timerId = null;

Changed July 19, 2011 01:21PM UTC by timmywil comment:12

resolution: fixed
status: closedreopened

You're right

Changed July 19, 2011 01:26PM UTC by timmywil comment:13

status: reopenedopen

For 1.6.3

Changed August 25, 2011 07:43PM UTC by timmywil comment:14

milestone: 1.next1.6.3
resolution: → fixed
status: openclosed

This is fixed for 1.6.3.