I have a clock in a block, and when my form performs an AJAX action (refreshing a table) the clock gets messed up. I haven't had time to look more closely, but it appears that a new instance of the clock starts up each time the AJAX even is invoked. Each instance seems to be changing the same block so I start seeing multiple times quickly appearing.

#7 1246680-clock-ajax-cache.patch3.72 KBtstoeckler
Test request sent.
[ View ]
#3 testajax.tgz686 bytesmlove_drupal


Mmmhhh, could you write-up a step by step list of things to do to reproduce this bug?
There was a similar kind of flicker-y behavior with the Overlay in Drupal 7, but it got fixed somehow before the release of Drupal 7.0.
I'm not really the AJAX guru, so there might well be a bug in this module, but I won't be able to debug this.

I'll see if I can break it down into a really small example and get back to you.

new686 bytes

I've attached a simple module that I've put together that can trigger this problem on a fresh install of Drupal 7.7 and the Clock module (including dependencies).

1) Untar and install the testajax.tgz module.

2) Using the Date module, create a Date format that will display seconds (like "Y-m-d H:i:s").

3) Add a Clock block anywhere on the page and make sure it is using the format you just created.

4) Go to /testajax on your Drupal site and press the "AJAX" button. The word "Test" will be replaced with the current unix time. Press it a couple of times.

It looks like each time it is pressed a new instance of the clock is started and tries to display (you get the number flickering).

I'm seeing this in other modules, too, like Block Refresh. A couple of AJAX calls from a form and they start refreshing like this, too. In the case of Block Refresh it can start causing a lot of traffic.

I'm hoping that I did something wrong in my AJAX calls that can be fixed, but it's a very simple test and I can't see what I've done wrong, if so.

Wow, that's very awesome, thanks! I'll try that out soon.

Super cool, thanks again.
I can now reproduce the problem.
I tried the whole thing on 7.x-1.x and couldn't reproduce it there. I think this could be a duplicate of #1192246: Disable Block Cache?, but I'm not sure. I'll try to get that one fixed in 7.x-2.x soon, and then we'll see.

After playing around with this and the Block Refresh module, I think I know what is going on:

When AJAX is used, I think Drupal reruns all of the functions attached to Drupal.behaviors. This means that the setInterval() is called again.

I believe you need to set a variable so your javascript already knows if the clock is running, and then skips initialization if it is true.

Status:Active» Needs review
new3.72 KB
Test request sent.
[ View ]

Here is a patch which fixes the problem.
Thanks again for your test module, that helped a lot in debugging this.
This also fixes #1192246: Disable Block Cache?, because it was necessary to fix that for this bug.

Committed to 7.x-2.x.
Thanks again!

It could still use a review, though. It would be awesome if you could report back if this fixed the problem.

I'll try to get to it shortly. I'm working on a different project at the moment and the one that was using the clock has fallen to the back-burner.

Thanks for working on the patch.

Status:Needs review» Fixed

Marking fixed. Please re-open or open a new issue, if the problem re-surfaces.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.