Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#7 | 1246680-clock-ajax-cache.patch | 3.72 KB | tstoeckler |
#3 | testajax.tgz | 686 bytes | mlove_drupal |
Comments
Comment #1
tstoecklerMmmhhh, 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.
Comment #2
mlove_drupal CreditAttribution: mlove_drupal commentedI'll see if I can break it down into a really small example and get back to you.
Comment #3
mlove_drupal CreditAttribution: mlove_drupal commentedI'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.
Comment #4
tstoecklerWow, that's very awesome, thanks! I'll try that out soon.
Comment #5
tstoecklerSuper 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.
Comment #6
mlove_drupal CreditAttribution: mlove_drupal commentedAfter 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.
Comment #7
tstoecklerHere 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.
Comment #8
tstoecklerhttp://drupal.org/commitlog/commit/12842/b9537f198e01e177d57495ba85da168...
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.
Comment #9
mlove_drupal CreditAttribution: mlove_drupal commentedI'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.
Comment #10
tstoecklerhttp://drupal.org/commitlog/commit/12842/7fba9686a7bddfd74b004f674b61953...
Comment #11
tstoecklerMarking fixed. Please re-open or open a new issue, if the problem re-surfaces.