I've turned on the cacheing on a Drupal site that has AddToAny Module installed. The strangest thing happens that on the first page load after the cache is cleared the popup works fine but on the fallowing loadings of the page the popup just doesn't appears anymore. I checked the source of the page and it apperas that the script that creates the box is not inserted anymore.

Comments

micropat’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

No other reports, and cannot reproduce yet. What are your settings in admin/config/development/performance?

ace11’s picture

Priority: Major » Critical
Status: Postponed (maintainer needs more info) » Active

This happens to mee too. Very strange behavior.

And also noticed that this same thing happens with 7.x-4.0 version.

ezman’s picture

I am seeing this too with 7.x-4.0

Performance settings are all checkboxes checked and dropdowns have 'none' selected.

If I clear all caches then the anonymous user can see the popup on the first page requested. Other pages do not show the popup. Revisiting the first page shows the popup.

I tried manually adding the script that creates the da2a object to my theme's script.js. The error in the javascript console about da2a not being defined goes away, but the popup still does not display.

Unchecking 'aggregate javascript files' does not fix the issue.

Unchecking 'cache blocks' appears to fix this issue for me. My AddToAny popup is in a block.

AshleyWilde69’s picture

I also have the block randomly disappearing. One minute its there the next its not displayed. Refresh and its there again. Then gone on the next page. Very frustrating.

Ashley :)

tim_dj’s picture

Issue summary: View changes

I've a similar problem. I have two addtoany blocks. One is added in a View. The other is normal addtoany block inserted through contexts.
When I clear text they are both visible. After that the bottom one is missing (the one inserted through context) using 7.x-4.5

tim_dj’s picture

I've figured out what my problem was. I had views cache. Output and query cache where on 5 minutes. This means the output of _addtoany_create_button() gets cached. Which causes it only to work after emptying cache because it won't execute the code in _addtoany_create_button() again with cache.

emilflatz’s picture

AddToAny block disappeared when I enabled cache block option in performance settings.
I installed Block Cache Alter, and on the block list page disabled the cache on AddToAny block.
Block reappeared again.

tim_dj’s picture

Javascript and css should be attached to block using #attached instead of doing it with drupal_add_js otherwise they won't be reloaded when block is in cache.

Shane Birley’s picture

Confirmed. Cache turned on, block disappears. Cache turned off either via Drupal performance or via Block Cache Alter it appears.

micropat’s picture

Category: Support request » Bug report
Priority: Critical » Major
Status: Active » Needs review

Switched to #attached as part of today's dev release.

Please try it and report back!

micropat’s picture

Status: Needs review » Fixed

Should be fixed in 7.x-4.6 since drupal_add_ functions are replaced with #attached.

Status: Fixed » Closed (fixed)

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

Shane Birley’s picture

Confirmed.

jamix’s picture

Status: Closed (fixed) » Active

Using 7.x-4.6 over here and the problem still exists. FYI, #attached still works via drupal_add_ under the hood.

robertragas’s picture

Yeah, I had the same problem. What I did was use hook_block_info_alter to turn off the caching for the addtoany block and then it worked.
Maybe just turn off the caching in the hook_block_info? Not sure if it would impact performance alot.

/**
 * Implementation of hook_block_info_alter().
 */
function hook_block_info_alter(&$blocks, $theme, $code_blocks) {
  // Loop through all the blocks.
  foreach ($blocks as $key => $value) {
    foreach ($value as $subkey => $subvalue) {
      // If block delta is addtoany change cache to -1.
      if ($subvalue['delta'] == 'addtoany_button') {
        $blocks[$key][$subkey]['cache']= -1;
      }
    }
  }
}
emanuelrighetto’s picture

Version: 7.x-3.1 » 7.x-4.7
Category: Bug report » Feature request

@Robert Ragas is right. And also his implementation of hook_block_info_alter() solves the problem of inline script when caching is on.

russellb’s picture

+1 for switching off the block cache on the add to any block

#15 is solving this for me so far

caspervoogt’s picture

Confirming this issue for 7.x-4.7 as well, and Robert's code solves it, though I think the Add To Any module's addtoany_block_view function should be adjusted to include the renderable array including CSS and JS, rather than using addtoany_page_alter() to attach the CSS/JS, no?

e.g.;

function addtoany_block_view($delta = 0){
    switch ($delta) {
      case 'addtoany_button':
        $block = array(
      'subject' => t('AddToAny'),
      'content' => array
      (
        '#markup' => _addtoany_create_button(menu_get_object()),
        '#attached' => array
        (
          'js' => array(''),//NEED TO GET ALL THE JS STUFF FROM addtoany_page_alter IN HERE!
          'css' => array(drupal_get_path('module', 'addtoany') . '/addtoany.css'),
        ),
      ),
    );
      break;
      return $block;
    }
  }

  • micropat committed 45b1d82 on 7.x-4.x
    Stop caching AddToAny blocks to fix issue #1315568
    
micropat’s picture

Title: Not adding the inline script if cache is turned on » Not adding the inline script if block cache is turned on
Status: Active » Fixed

Version 7.x-4.8 turns off caching on AddToAny blocks to resolve this issue.

Status: Fixed » Closed (fixed)

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