Incompatibility with Drupal 11/jQuery 4

Created on 9 August 2024, 2 months ago
Updated 20 September 2024, 27 days ago

Problem/Motivation

The Slick (both module and the library itself) use jQuery.type(), which is deprecated and no longer available in jQuery 4, which is used in Drupal 11. Therefore neither the module nor the library work out of the box in Drupal 11 installations.

Steps to reproduce

Install the Slick in Drupal 11.

Proposed resolution

All occurences of jQuery.type() must be rewritten to js's typeof. The Slick library itself must be patched as well. Only after that I was able to make it work as expected.

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇿Czech Republic petrsocha

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

Comments & Activities

  • Issue created by @petrsocha
  • Status changed to Active 2 months ago
  • 🇮🇩Indonesia gausarts

    Thank you.

    • gausarts committed 299772e4 on 3.0.x
      Issue #3467129 by petrsocha: Incompatibility with Drupal 11/jQuery 4
      
  • Status changed to Fixed 2 months ago
  • 🇮🇩Indonesia gausarts

    Thank you for contribution.

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

  • 🇨🇦Canada dadderley Vancouver

    I have a new installation using Drupal 11.0.4.
    I cannot get this to work.

    I use Slick Carousel 3.0.3 on a few Drupal 10 sites with no problem.
    This is a Drupal 11 specific problem.

  • have the same problem on drupal 11 with slick :(

  • Update: I have resolved the issue with Slick Carousel in Drupal 11.

    The problem was due to the use of $.type() in the slick.js file, which is no longer supported in jQuery 4 used by Drupal 11. To fix this, I replaced all instances of $.type() with appropriate native JavaScript methods.

    Here are the specific changes I made in /libraries/slick-carousel/slick/slick.js:

    1. Replace $.type() when checking for an array:

      Before:

      if ( $.type(responsiveSettings) === 'array' && responsiveSettings.length ) {

      After:

      if ( Array.isArray(responsiveSettings) && responsiveSettings.length ) {
    2. Replace $.type() when checking for an object:

      Before:

      if( $.type( arguments[0] ) === 'object' ) {

      After:

      if ( typeof arguments[0] === 'object' && arguments[0] !== null && !Array.isArray(arguments[0]) ) {
    3. Replace $.type() when checking for a string:

      Before:

      else if ( $.type( arguments[0] ) === 'string' ) {

      After:

      else if ( typeof arguments[0] === 'string' ) {
    4. Replace $.type() when checking if an argument is an array:

      Before:

      if ( arguments[0] === 'responsive' && $.type( arguments[1] ) === 'array' ) {

      After:

      if ( arguments[0] === 'responsive' && Array.isArray( arguments[1] ) ) {
    5. Replace $.type() when ensuring a property is not an array:

      Before:

      if( $.type( _.options.responsive ) !== 'array' ) {

      After:

      if ( !Array.isArray( _.options.responsive ) ) {

    After making these changes, I minified the updated slick.js file using UglifyJS to create a new slick.min.js. I replaced the old slick.min.js with this new one.

    Once these steps were completed, the slider started working correctly again!

    Note: I have double-checked all the code snippets to ensure they match exactly what I provided earlier.

  • 🇻🇳Vietnam tuthanh

    #8 is good. Thanks terminator727. I applied the same tricks and Slick is working properly in Drupal 11 and JQuery 4.

Production build 0.71.5 2024