Broken menu visualization for anonymous user since drupal 10.4

Created on 8 January 2025, 3 months ago

Problem/Motivation

After the update to Drupal 10.4, main menu for anonymous users only is no more displayed correctly: no working breakpoint, always open drop-menu shown just as an HTML unordered list

Steps to reproduce

My Drupal site is actually running with PHP 8.2.10, but I have the same problem with PHP 8.3.14.
No such a problem up to the last Drupal 10.3 release
I updated as usual drupal manually (it's impossible for me to run composer on the hosting server) to 10.4.0 and the problem above arose.
Only anonymous users can see this problem. Responsive menu is working correctly for logged or admin users.
Same problem with Drupal 10.4.1
Same problem with both using adaptivetheme 7.1.0 and adaptivetheme 8.x-5.4

Proposed resolution

None.
I couldn't find any useful/missing setting in Roles or Permissions.
The issue should be necessary related to a change from Drupal 10.3 to Drupal 10.4
Any dependecy gone missing in the update?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

7.1

Component

Miscellaneous

Created by

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

Comments & Activities

  • Issue created by @ilcalle78
  • πŸ‡ΊπŸ‡ΈUnited States wmfinck

    Thank you I have this same problem, and this post came up first when I searched Google for "drupal adaptive menus expanded for anonymous users". I just noticed the problem this morning, since I rarely visit sites I manage without being logged in, once development is completed.

    I have eight D10 sites, all using this theme, all on the same server. This morning I set out to update them all to D10.4 and the very first one I updated is having this problem, so I will stop here for now. This also exemplifies why I have never automated my upgrades.

  • πŸ‡·πŸ‡ΊRussia a_sh

    I have this same problem too.

    Any solution?

  • Please check issue 3495319 πŸ› Uncaught TypeError: Cannot read properties of undefined (reading 'theme') Active . I guess the asset ordering change is causing this.

  • I don't get any error, neither in log nor using "verbose" mode, and the same happens after cache cleaning.

    By the way I noticed that also the SLIDESHOW doesn't work for anonymous users, while it still works correctly for logged ones.

  • Yes, same kind of error when using anonymous

    js_2JgqE6kUMjTFgeB0GkUbHSTkMck6du2Uq8cNsaDYP10.js?scope=footer&delta=0...-VM8Q:22 Uncaught TypeError: Cannot read properties of undefined (reading 'theme')
        at Object.attach (js_fE8OE5f7_hWnFmvQEIqXIGJtl-8CIT3r9ZiZC5kNeGc.js?scope=footer&delta=2...-VM8Q:2:139)
        at js_2JgqE6kUMjTFgeB0GkUbHSTkMck6du2Uq8cNsaDYP10.js?scope=footer&delta=0...-VM8Q:22:427
        at Array.forEach (<anonymous>)
        at Object.attachBehaviors (js_2JgqE6kUMjTFgeB0GkUbHSTkMck6du2Uq8cNsaDYP10.js?scope=footer&delta=0...-VM8Q:22:353)
        at js_2JgqE6kUMjTFgeB0GkUbHSTkMck6du2Uq8cNsaDYP10.js?scope=footer&delta=0...-VM8Q:23:373
        at HTMLDocument.listener (js_2JgqE6kUMjTFgeB0GkUbHSTkMck6du2Uq8cNsaDYP10.js?scope=footer&delta=0...-VM8Q:23:161)
  • πŸ‡ͺπŸ‡ΈSpain hip GijΓ³n, Asturias

    Following. Same here (broke my theme in different points).

  • Hi everyone,

    I'm trying to work on this - the theme isn't abandoned. Thank you to all of those who have reached out - I have a busy full-time job, but I am trying to work on this theme. That being said, if anyone wants to help with development or knows someone who wants to help with development, please let me know, I'd greatly appreciate it.

  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    Problem

    The problem here is, that the broken JavaScript functions try to read the current theme name from settings['ajaxPageState']['theme']. When your users are logged in they can probably see the toolbar or some other component, that makes sure, that ajaxPageState is not empty. But when you're logged out, settings['ajaxPageState']['theme'] is empty, which leads to the issue.

    To better understand the problem, look at at.flexsliderSettings.js for example, at around line 8:

    Drupal.behaviors.atFS = {
        attach: function (context, settings) {
    
          var activeTheme = settings['ajaxPageState']['theme'],
              slideshowSettings = settings[activeTheme]['at_slideshows'];
    

    If you replace 'settings['ajaxPageState']['theme']' with your active theme's name, the issue is resolved.

    Also those scripts seem to have the same problem:

    β€’ at.breakpoints.min.js
    β€’ at.responsiveMenus.min.js
    β€’ at.flexsliderSettings.min.js

    Proposed resolution

    As a temporary workaround I updated functionat_core_preprocess(&$variables) in adaptivetheme/at_core/includes/preprocess.inc at around line 30. Here I store the theme's name in the drupalSettings object.

    $variables['page']['#attached']['drupalSettings']['at_current_theme_name'] = $theme['name'];
    

    In all involved JavaScript files I replace settings['ajaxPageState']['theme'] with my new variable that holds the theme name.

    My updated preprocess.inc looks something like that:

    /**
     * Preprocess variables for all templates.
     *
     * @param $variables
     */
    function at_core_preprocess(&$variables) {
      // Add theme variables. template_preprocess is hit many times so we statically
      // cache $theme.
      $theme = &drupal_static(__FUNCTION__);
      if (!isset($theme)) {
        $data = new ThemeConfig(\Drupal::theme()->getActiveTheme()->getName());
        $theme = $data->getConfig();
      }
      $variables['theme'] = $theme;
    
      // Add current theme name to drupalSettings.
      $variables['page']['#attached']['drupalSettings']['at_current_theme_name'] = $theme['name'];
    
      // Set global is_front.
      try {
    

    In the involved JavaScript files I replace settings['ajaxPageState']['theme'] with my custom variable settings.at_current_theme_name.
    The updated at.flexsliderSettings.js looks like this:

    (function ($, Drupal) {
    
      "use strict";
    
      Drupal.behaviors.atFS = {
        attach: function (context, settings) {
    
          var activeTheme = settings.at_current_theme_name;
          var slideshowSettings = settings[activeTheme]['at_slideshows'];
    
          for (var item in slideshowSettings) {
    
  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    Here's a patch that fixes issue #3498246 as described in #9. Seems to work with 7.* as well as 8.x-5.*
    Unsure if this is the most elegant solution, but at least it fixes our broken sites for now :)

    Apply the patch

    • Go to your site's themes/contrib/adaptivetheme/ directory
    • Run patch -p1 < /path/to/the/patchfile.patch
  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna
  • Thanks for the patch electric.larry, but it does not work here. I patched by adding it to composer.json:

            "patches": {
                "drupal/adaptivetheme": {
                    "Broken menu visualization for anonymous user since drupal 10.4": "https://www.drupal.org/files/issues/2025-01-23/adaptivetheme-broken-menu-since-drupal104-3498246.patch"
                }

    I am using AdaptiveTheme 8.x-5.4 and updated my testsite to Drupal 10.4.1 with your patch, but my menu is still broken in responsive mode. I am using the "Drop menu" responsive style in the AdaptiveTheme settings:

  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    Is the patch applied successfully? Did you rebuild the cache?
    Could you please check your browser console and post the error message(s) that you can see there?

  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    There was a problem in the previous approach.

    I had to move $variables['#attached']['drupalSettings']['at_current_theme_name'] = $active_theme_name; to the at_core_preprocess_page() function to make it work on another test site.

    @sd123 could you please try again with the new patch from #14?

  • I did drush cr, disabled all css and js aggregation, disabled all JS and HTML minification, and disabled AdvAgg. The menu is still broken.

    I am using the following patches:

  • Thank you electric.larry, but it didn't work for me too.
    I tried both patches.
    But at least my php errors decreased from 3 to 2.

  • πŸ‡ΊπŸ‡ΈUnited States drupal_rogue

    I can confirm that #14 worked for my site. Thank you.

  • Ok. Now it works for me too!
    But it worked only when, after applying #14, I also modified at_core.libraries.yml in order to use the standard version and not the minified version of those three javascripts.
    Like this:

    [...]
    
    # Breakpoints
    at.breakpoints:
      version: VERSION
      js:
        #scripts/min/at.breakpoints.min.js: { minified: true }
        scripts/min/matchMedia.min.js: { minified: true }
        scripts/min/matchMedia.addListener.min.js: { minified: true }
        scripts/at.breakpoints.js: {}
    
    [...]
    
    # Responsive Menus
    at.responsivemenus:
      version: VERSION
      js:
        #scripts/min/at.responsiveMenus.min.js: { minified: true }
        scripts/min/matchMedia.min.js: { minified: true }
        scripts/min/matchMedia.addListener.min.js: { minified: true }
        scripts/at.responsiveMenus.js: {}
    
    [...]
    
    # AT Slideshow settings
    at.slideshow_settings:
      version: VERSION
      js:
        #scripts/min/at.flexsliderSettings.min.js: { minified: true }
        scripts/at.flexsliderSettings.js: {}
    
    [...]
    

    So, probably for some reason the minified version is not equivalent (at least in my case).
    Sorry, but I don't know how to create a patch.

  • I got it temporarily working that way ilcalle78, but after switching on/off aggregation settings and cleaning caches in between, it broke again and it stays broken even after changing to previous settings.

  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    I'm sorry but it's hard to remotely debug that problem and I don't have time to get into this further. We'll have to wait for the module maintainer to look at the problem.

    But as a temporary workaround what @ilcalle78 suggested seems good to me. Make sure that the unminified javascript files are used and that your caches are properly cleared. drush cr alone will not always pick up changes to the .yml files. Also run "drush cc css-js" or restart webserver to definitly clear all cached stuff.

    What the patch does is making the theme name available in the Drupal settings object: settings.at_current_theme_name.

    To manually debug and workaround your problem, set a breakpoint where the undefined reading 'theme' error happens and make sure that the call to settings['ajaxPageState']['theme'] is properly repalced with settings.at_current_theme_name. If you can still see the call to settings['ajaxPageState']['theme'], find out how to replace it.

    Hope this helps a little.

  • A comment for @sd123: mine is working with "JS aggregation on", but sometimes in case of error the only workaround is to disable it (see here β†’ )

  • Thanks for the help ilcalle78 and electric.larry. I am using Minify JS β†’ module and that was probably causing this.

    I also saw Minify JS was able to make even the minified versions provided by AdaptiveTheme smaller. Hence, I disabled all minified versions to let Minify JS do all the minification work. I created a patch for this. It seems to work on my staging site and I will keep it running for some time before switching production.

    Is anybody interested in the minified versions of at_core JS libraries created by Minify JS? Then I can manually download them and upload them here and they can then eventually be added to the source code. Or isn't that the way to create those minified versions taking security in mind?

    At least, I can confirm the minified libraries provided by AdaptiveTheme are currently causing troubles with electric.larry's patch. So, either his patch needs to be updated, or some of the minified libraries needs to be replaced. Deleting them and advising to use Minify JS is also an option.

  • Too bad. It broke again after less than a day. :-(

    Anonymous users get a broken menu. It only works when logged in.

    I got it working again after deleting all minified Javascript and creating those again.

    There still is a bug somewhere...

  • Once again it broke and I "fixed" it by 'drush cc css-js' and then pushing on the clean all caches button at /admin/config/development/performance.

    I now also disabled the option 'Use Minified JavaScript files.' to see if that will make a difference.

    If that helps, I will try to put some files on the Exclusion List of MinifyJS as a temporary solution.

    To be continued.

  • This is made it's way into the new release.

  • πŸ‡·πŸ‡ΊRussia urix

    Updating to 7.1.1 fixes the problem.

  • Ok, so I applied electric.larry's patch in #14 and my patch in #22 and did some testing with MinifyJS exclusion list.

    So far (I will keep it running on staging for some time to be sure), I need to add the following scripts to that list to get the menu working:

    *scripts/at.breakpoints.js
    *scripts/at.responsiveMenus.js
    *scripts/at.windowSize.js

    If I do not add those scripts, they get minified by MinifyJS and those versions still break the menu. The same is true for the minified versions supplied with AdaptiveTheme.

    Maybe the current fix is using variables in those scripts that are changed when the scripts get minified?

  • I confirm that 7.1.1 is working for me too.
    Thank you Matt

  • πŸ‡ΊπŸ‡ΈUnited States adrianm6254

    We upgraded to 7.1.1 and all is well.
    Thanks!

  • πŸ‡¦πŸ‡ΉAustria electric.larry Vienna

    Updated to 7.1.1 and AT Tool 3.x. Works well on 3 different sites.

    Imho we can mark this one fixed, @mattbloomfield.

    @sd123, it seems to me, you're running in some other problem connected with your setup.

  • This seems to be related to the issue https://www.drupal.org/project/at_theme/issues/3495512 πŸ› upgrades to 10.4.0 or 11.1.0 change layout to single column Active
    While the main menu problem is fixed and remains fixed even after the upgrade to Drupal 11, the other problem of all theme regions appearing in a single column regardless of the screen width is there after the upgrade to Drupal 11. The 7.1.1 version fixes that problem for Drupal 10.4.1, but not for Drupal 11.

  • Milan, can you also try my patch in comment #22 to disable all minified Javascript files to see if that helps?

    Make sure to disable MinifyJS module if you are using that (or put all those scripts on the exclusion list) and to clean all caches afterwards.

    I am still using 8.x-5.4 and Drupal 10.4.1. Disabling minification of at.breakpoints.js, at.responsiveMenus.js, and scripts/at.windowSize.js is a workaround fix here.

  • Hi sd123,

    I've tried your patch and it didn't help. The patching operation was successful, then I cleared Drupal cache, did updatedb, and also cleared browser cache. Tried logged in and logged out. It made no difference.

  • πŸ‡ΊπŸ‡ΈUnited States wmfinck

    In advance, sorry I cannot help, and all I can do is explain some troubles I am having. So I am sharing this hoping that it gives someone who knows the code a clue of what might be happening. The recent security release compelled me to update sites which I was holding out on until this is fully resolved.

    After updating, I am still having the menu issue on a handful of sites, but most of the sites are good. So I installed the superfish module on those few sites to get around that problem, and it works well but it clashes with the theme.

    I have two websites with slideshows above the fold. On the first, a Views slideshow only appears for anonymous users, and there is only a blank space for users who are logged in. On the second site, an Adaptive slideshow appears for logged in users, but not for anonymous users, and it leaves no blank space.

    I cannot find any particular reason for any of this behavior, but thought the information might be of help to a developer. I have been through all the usual steps, cleared caches often, turning caching off, experimenting with different settings. I checked and rechecked, and saved Theme and Block settings multiple times, all to no avail.

    Maybe one or two of the websites with the menu issues are complex, but a few are just very plain sites with only a few entries and a few added modules, where I would never expect an issue.

    In any event, I appreciate the work which goes into this theme. I would gladly use a "buy me a coffee" button if I saw one! In the past, I subscribed to Jeff Burnz's website, to help support his efforts, but adaptivetheme.com is gone now, even if it is still in the sidebar description for this theme.

  • Status changed to RTBC 26 days ago
  • ok, I got it working. I can confirm the patch does not work as intended with version 8.x-5.4. The recommended project version does not work well with Drupal 10.4.x.

    Shouldn't version 7.1.1 become the recommended branch? Or shouldn't the 8.x-5.4 branch also be fixed?

Production build 0.71.5 2024