Slick does not initialize for admin (and possibly other cases multiple attach/AJAX calls)

Created on 25 July 2025, 5 days ago

Problem/Motivation

We've recently seen that Slick sliders are not initialized for admin users, while they are working perfectly for regular / anonymous visitors.
Tracking this down, we found out that the reason is in slick.load(.min).js:

As admin, there are multiple elements loaded via AJAX (especially the admin menus), causing Drupal.behaviors.slick to be called multiple times.
For visitors, there is only one call, so they don't run into this edge-case.

The last time it's called, the context is document, which is the context that contains the slick sliders.

/**
   * Attaches slick behavior to HTML element identified by CSS selector .slick.
   *
   * @type {Drupal~behavior}
   */
  Drupal.behaviors.slick = {
    attach: function (context) {
      _d.once(doSlick, _id, _element, context); // <<<<<<<<<<
    },

executes doSlick() only on the first (admin menu ajax) call, which has no sliders in context!
Further calls with the correct context don't execute the doSlick() any more so the sliders in the different context don't get initialized

I guess this edge-case happens especially, because the other calls are earlier than document.

Steps to reproduce

  1. Place a slick slider, e.g. a views block on the page and see it working
  2. Use https://www.drupal.org/project/admin_toolbar or any other modules using AJAX calls before the document context
  3. See the slick slider broken as admin, with previous Drupal.attach() calls!

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    I'm not totally sure if this is a bug in blazy.once or in slick. We've seen this on D11 projects, I'll try to find out, if same happens in D10.

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Okay, rewriting the attach() to once() works flawlessly:

        attach: function (context) {
          // _d.once(doSlick, _id, _element, context);
          once(_id, _element, context).forEach((mySlider) => {
            doSlick(mySlider);
          });
        },
    

    So I guess this is really a blazy.once(.min).js bug?

  • 🇩🇪Germany Anybody Porta Westfalica

    Prepared a hotfix on #6 for now. I'm really interested what causes this and how to properly fix it. Maybe it's the BigPipe/Dom/AJAX handling workarounds in Blazy?

    Feel free to move this issue over to Blazy, if it belongs there. Thanks!

  • Pipeline finished with Success
    5 days ago
    Total: 166s
    #556770
  • 🇩🇪Germany Anybody Porta Westfalica

    Hotfix MR!15 as static patch attached.

  • 🇩🇪Germany Anybody Porta Westfalica
  • Pipeline finished with Success
    5 days ago
    Total: 246s
    #556807
  • 🇩🇪Germany Anybody Porta Westfalica
  • Pipeline finished with Success
    5 days ago
    Total: 276s
    #556813
  • 🇮🇩Indonesia gausarts

    Thank you.

    > Slick sliders are not initialized for admin users
    Is it only bad at admin pages, or any pages for admin?

    We need more info to narrow down triggering contexts:

    1. What Drupal version? Fine at D10?
    2. Slick version according to the supported one? See project home for sure, also apply D11 fixes if D11.
    3. Is it fine without BigPipe?

    The only reason Blazy extended core once was to deal with known BigPipe glitches given various contexts: AJAX in infinite pagers vs regular AJAX, multiple calls/renders of BigPipe causing particular initializes (library/script loaders) messed up, multiple Slick sliders in infinite pagers, etc.

    So the fix should go to Blazy, if later proven BigPipe, or in this module if anything else like D11 compat, etc.

  • 🇩🇪Germany Anybody Porta Westfalica

    Hi @gausarts thanks for your quick reply!

    I'l try debugging this deeper and will also try to reproduce this in vanilla Drupal using the admin menu modules, so hopefully you can also easily reproduce this. Very busy days, hopefully this week!

  • 🇮🇩Indonesia gausarts

    Take your time :)

    On second thought, enabling Use AJAX option at Views UI RHS, should fix it.

    It is less expensive and problematic than any proposed solutions above. More efficient than loading AJAX scripts for all Views blocks.

    UI fixes are equally valid as codes.

    Pretty much similar to the linked issue, only less clear :)

    Feel free to re-open if persists, though. Be sure to reply to my previous questions properly for better scopes.

  • 🇩🇪Germany Anybody Porta Westfalica

    @gausarts thanks! Enabling "use ajax" is also a nice workaround option, but I think it's just too dangerous. Slick views don't need AJAX logically, right and this happens with any slick view if admin_toolbar is used.

    So any site maintainer changing the views setting would break it... From my perspective it needs to be fixed in code...

  • 🇮🇩Indonesia gausarts

    Actually I couldn't reproduce your issue with D11 and BigPipe.

    But I understand the underlying problem as previously mentioned.

    I added a new commit to avoid enabling Views AJAX without unneeded AJAX inclusion or risking a regression by modifying the existing scripts:
    https://git.drupalcode.org/project/blazy/-/commit/62ec0b769337ef6aeefe78...

    If you could test out the latest Blazy DEV and confirm OK, we'd probably have a new release soon.

    Thank you.

Production build 0.71.5 2024