Problem/Motivation
Calling this a regression because I think it surfaced with #3568566: Olivero's secondary menus inoperable when authenticated & BigPipe present.
It appears that the second-level-navigation.js file gets loaded as a dependency of the olivero/search-wide library, even when there are no menu items.
This causes a JavaScript error when the ESC key is pressed, which prevents the mobile menu from closing:
second-level-navigation.js?v=12.0-dev:108 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
at Object.areAnySubNavsOpen (second-level-navigation.js?v=12.0-dev:108:25)
at HTMLDocument.<anonymous> (navigation.js?v=12.0-dev:53:27)
areAnySubNavsOpen @ second-level-navigation.js?v=12.0-dev:108
(anonymous) @ navigation.js?v=12.0-dev:53
Most sites won't have an empty main menu, but I found that the problem also occurs with the nightwatch_a11y_testing profile and causes tests for #3338664: Migrate Nightwatch Axe tests to PHPUnit to fail by default because of the console error.
Steps to reproduce
- Install with the Standard profile.
- Log in as admin.
- Go to
/admin/structure/menu/manage/main. - Uncheck the box in the "Enabled" column for all menu items.
- Click "Save"
- Enable the Search module.
- Go to the front (Home) page.
- Reduce viewport width until the "mobile" menu toggle button appears (aka, the hamburger).
- Click the toggle button to expand the menu.
- Press the
ESCkey.
Expected behavior
- The menu closes.
- JavaScript errors do not appear in the browser console.
Actual behavior
- The menu does not close.
- JavaScript errors do appear in the browser console.
Note: The console error appears even when the menu isn't open, but AFAICT that case doesn't break functionality.
Proposed resolution
Copy the following change from #3515403: Update to selenium/standalone-chrome:133 to an MR for this issue:
- let secondLevelNavMenus;
+ let secondLevelNavMenus = [];
Remaining tasks
- Create MR.
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | patch-After.png | 57.38 KB | rupeshghar |
| #7 | patch-before.png | 47.64 KB | rupeshghar |
| #7 | olivero-mobile_menu_not_closing_on_esc-3584314.patch | 476 bytes | rupeshghar |
Issue fork drupal-3584314
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kentr commentedComment #3
kentr commentedComment #4
kentr commentedComment #6
longwaveRediscovered this over in #3515403: Update to selenium/standalone-chrome:133 which triggers this same bug from a test (older Chrome did not). The fix is a one liner:
Comment #7
rupeshghar commentedRoot cause: with an empty main menu, secondLevelNavMenus stays undefined since init() never runs. When Search is enabled, navigation.js's Escape-key handler still calls areAnySubNavsOpen() → secondLevelNavMenus.forEach(...), throwing Cannot read properties of undefined (reading 'forEach') and aborting before the mobile menu actually closes.
Fix per #6: initialize secondLevelNavMenus = []. Verified with a headless-browser check — before: Escape throws and menu stays open; after: no errors, menu closes. Patch attached.
Comment #8
smustgrave commentedFixes need to be in MRs for review please
Comment #9
longwaveThis was already fixed in main and 11.x as part of #3515403: Update to selenium/standalone-chrome:133 but I think we could backport the fix itself to 11.4.x and 10.6.x here.
Comment #10
kentr commented@longwave:
For that, does it need an MR here with this change?
Comment #11
longwaveYes, that's all, not even sure we need test coverage here really.
Comment #12
kentr commentedComment #14
quietone commentedOlivero is now a contributed project