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 === ''

Issue fork drupal-3407067

Command icon 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

tedbow created an issue. See original summary.

tedbow’s picture

Status: Active » Needs review
Issue tags: +Needs tests
tedbow’s picture

Title: message.js assumes status messages element has child element, incompatible default template » message.js doesn't status messages no child element but whitespace, incompatible default template
tedbow’s picture

Title: message.js doesn't status messages no child element but whitespace, incompatible default template » message.js doesn't work status messages element with no child element but whitespace, incompatible default template
smustgrave’s picture

Status: Needs review » Needs work

No test failure is probably a good sign.

Could steps to reproduce be added please.

tim bozeman’s picture

Issue summary: View changes
Status: Needs work » Needs review

Added testing instructions.

tim bozeman’s picture

Issue summary: View changes
tim bozeman’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

Thanks for adding those! Was previously tagged for tests too in #3

tim bozeman’s picture

Status: Needs work » Needs review

Thank you smustgrave

I added a test and it looks like they are all passing.

smustgrave’s picture

Status: Needs review » Needs work

Possible to merge this into JsMessageTest to keep things well grouped.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.