Sometimes Drupal.blazy.init is null, how to reload?

Created on 20 September 2023, about 1 year ago
Updated 17 January 2024, 10 months ago

Problem/Motivation

Its not very often, but we do encounter instances where a page will load with no images. Looking into console we can see Drupal.blazy.init is null. Running Drupal.blazy.isLoaded() confirms its not loaded.

However, I haven't been able to get blazy to reload. Ive included a screenshot to illustrate. I found this ticket https://www.drupal.org/project/blazy/issues/3154895 but since init is null we can not use Drupal.blazy.init.load() and Drupal.blazy.load() does not seem to be working either.

Steps to reproduce

Honestly, I don't know. Its very intermittent. From what I've seen so far, it seems to be when opening a page in a new tab/window.

Question

If a page ends up with Drupal.blazy.init = null, how can we reload blazy?

Thanks!

💬 Support request
Status

Fixed

Version

2.16

Component

JavaScript

Created by

🇺🇸United States justclint

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @justclint
  • 🇮🇩Indonesia gausarts

    I am not sure, but perhaps your calling JS was too early in the script orders?

    Tried to make it depend on blazy/load or blazy/compat?

    If anything fails, try a little magic of setTimeout(myfunction, 911);.

  • 🇮🇩Indonesia gausarts

    Just in case an oversight, putting your code inside Drupal.behaviors.myFunction.attach {} should normally work.

    Another decent magic is dBlazy.ready(myfunction, 911);, similar to jQuery.().ready(myfunction, 911); for very rare situations:
    > The .ready() method offers a way to run JavaScript code as soon as the page's Document Object Model (DOM) becomes safe to manipulate.

  • 🇺🇸United States justclint

    Thanks @gausarts!

    Im adding the blazy/load dependency higher up in our theme to see if that remedies the problem. If I see this issue again Ill try the dBlazy.ready method.

  • 🇮🇩Indonesia gausarts

    Got it, thanks.

    Looking forward to hearing the intermittent fixed before closing this.

  • Status changed to Fixed about 1 year ago
  • 🇮🇩Indonesia gausarts

    If #2 and #3 do not work, the last I could think of:

    // See blazy.load.js.
    dBlazy.once.removeSafely('b-root', 'body', document);
    Drupal.attachBehaviors(document.body);

    Minor housekeeping for 2.18.
    Feel free to share your solutions.

    Thank you.

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

  • Status changed to Fixed 10 months ago
  • 🇺🇸United States justclint

    @gausarts, apologies for delayed reply. Its just taken a while to monitor and diagnose. Your recommendation about reattaching the behaviors did seem to reduce the issue by about 80-90%. Although it was still occurring, it did point us in the right direction and was able to track this back to this issue:

    https://www.drupal.org/project/drupal/issues/3105024 🐛 Drupal main javascript file can't be loaded with "defer" attribute after upgrade to 8.8.1 Fixed

    So just want to mention in case anyone comes across this. The is not a blazy issue. Ultimately applying this solved the problem:

    https://www.drupal.org/project/advagg/issues/3046173#comment-14078683

Production build 0.71.5 2024