message.js doesn't work status messages element with no child element but whitespace, incompatible default template

Created on 8 December 2023, about 1 year ago
Updated 10 December 2023, about 1 year ago

Problem/Motivation

Found in πŸ› Exceptions in batch no longer are shown on the page: Javascript error Fixed 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

Proposed resolution

Check wrapper.childElementCount === 0 instead of wrapper.innerHTML === ''

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
JavascriptΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024