Problem/Motivation
For anonymous users, the javascript file admin-toolbar-wrapper.js gets loaded for some reason that I could figure out. That then issues the following error on the browser console:
Uncaught TypeError: doc.querySelector(...) is null
attach https://www.example.com/core/modules/navigation/js/admin-toolbar-wrapper.js?v=10.4.0:71
attach https://www.example.com/core/modules/navigation/js/admin-toolbar-wrapper.js?v=10.4.0:158
attachBehaviors https://www.example.com/core/misc/drupal.js?v=10.4.0:166
attachBehaviors https://www.example.com/core/misc/drupal.js?v=10.4.0:162
<anonymous> https://www.example.com/core/misc/drupal.init.js?v=10.4.0:32
listener https://www.example.com/core/misc/drupal.init.js?v=10.4.0:20
This is due to the following code:
doc.querySelector('.admin-toolbar').dispatchEvent(
new CustomEvent(SIDEBAR_CONTENT_EVENT, {
detail: {
state: newState,
},
}),
);
Proposed resolution
Check for .admin-toolbar being present.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | drupal-3496541-6.patch | 2.72 KB | grimreaper |
Issue fork drupal-3496541
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:
- 3496541-admin-toolbar-wrapper-uncaught-typeerror
changes, plain diff MR !10737
Comments
Comment #3
jurgenhaasComment #4
finnsky commentedThank you for fix. Actually it is interesting why toolbar js loaded for anonymous.
Comment #5
jurgenhaasYeah, that caught me by surprise too. I was trying to determine where this is coming from, but I wasn't able to find out. It looks like it comes from the NavigationLayout, however, that shouldn't be touched either.
Comment #6
grimreaperHi,
Thanks for the fix! I have the same problem on 10.4.
Here is a patch from the MR for Composer usage until it is merged.
Comment #7
finnsky commentedIt still seems to me that in this task it is much more important to understand why the script is loaded in the wrong place than to fix the script directly. This is also a bug and a much more serious bug.
@grimreaper,
Maybe you have steps to reproduce? A list of third-party modules and some other details?
Comment #8
grimreaperI found my culprit...
https://git.drupalcode.org/project/navigation_extra_tools/-/blob/1.1.x/n...
No check at all if the navigation is present or not.
I will create an issue on this project.
Comment #9
larowlanLeft one comment on the MR, thanks
Comment #10
jurgenhaas@grimreaper thanks for the tip in #8, turns out it was the same issue here. Linking to #3497060: Add library only if needed for others who may come along here.
Even if this is certainly an issue in contrib, the safeguard in the js file still seems to make sense.
Comment #11
smustgrave commentedFeedback appears to be addressed
Comment #13
nod_Committed and pushed 554b7c600ad to 11.x and b5ccec7567d to 11.1.x and 07ae29edb49 to 10.5.x. Thanks!
Comment #17
nod_Comment #18
nod_