Problem/Motivation
Found in #3406612: Exceptions in batch no longer are shown on the page: Javascript error where we had to use olivero as the test them because the message.js does not work with the stark theme.
This is because core/modules/system/templates/status-messages.html.twig does not print anything under the top level div if there are no messages.
in core/misc/message.js we have
return wrapper.innerHTML === ''
? Drupal.Message.messageInternalWrapper(wrapper)
: wrapper.firstElementChild;
But wrapper.innerHTML !== '' because there is return character. Any other character would also make it break. So in this case wrapper.firstElementChild will be NULL.
We could change the template but any contrib or custom template with this would also break.
Steps to reproduce
- Using the stark theme (or many others)
- On a fresh page load, run
(new Drupal.Message()).clear();in the browsers JS console - The code will go this.messageWrapper.querySelectorAll, but messageWrapper will be null
Proposed resolution
Check wrapper.childElementCount === 0 instead of wrapper.innerHTML === ''
Remaining tasks
Review
Issue fork drupal-3407067
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 #3
tedbowComment #4
tedbowComment #5
tedbowComment #6
smustgrave commentedNo test failure is probably a good sign.
Could steps to reproduce be added please.
Comment #7
tim bozeman commentedAdded testing instructions.
Comment #8
tim bozeman commentedComment #9
tim bozeman commentedComment #10
smustgrave commentedThanks for adding those! Was previously tagged for tests too in #3
Comment #11
tim bozeman commentedThank you smustgrave
I added a test and it looks like they are all passing.
Comment #12
smustgrave commentedPossible to merge this into JsMessageTest to keep things well grouped.
Comment #15
quietone commentedCame across this while working on deprecating Olivero.
For #12, I simply renamed the test file, mostly because the existing test has setup function that this new test does not need.
Comment #16
smustgrave commentedSmall comments on the MR.
Comment #17
quietone commentedComment #18
quietone commentedComment #19
quietone commentedBack to needs review for the recent changes.