The core/drupal.message library requires a status_messages render element

Created on 23 October 2023, about 1 year ago
Updated 11 July 2024, 5 months ago

Problem/Motivation

In message.js there is JS that will result in error if a status messages element is not present

 static defaultWrapper() {
      let wrapper = document.querySelector('[data-drupal-messages]');
      if (!wrapper) {
        wrapper = document.querySelector('[data-drupal-messages-fallback]')z;
        wrapper.removeAttribute('data-drupal-messages-fallback');
        wrapper.setAttribute('data-drupal-messages', '');
        wrapper.classList.remove('hidden');
      }
      return wrapper.innerHTML === ''
        ? Drupal.Message.messageInternalWrapper(wrapper)
        : wrapper.firstElementChild;
    }

Prior to 🐛 Ajax errors are not communicated through the UI Fixed , core/drupal.messages was only loaded via the status_messages render element. Since that issue, core/drupal.ajax also loads core/drupal.messages, without there necessarily being a status_messages element on the page. If there is no status messages render element and Ajax needs to report a problem, there will be an execution-breaking JS error due to defaultWrapper() being called without the elements it expects available.

This causes 🐛 Exceptions in batch no longer are shown on the page: Javascript error Fixed but wasn't notice because there not tests for errors showing up on the batch page

Running into this IRL otherwise is less likely since most sites have a status messages element loading somewhere on any given page. It's more likely for this to occur in an automated test as those are scenarios where only the subjects under testing are on-page.

Steps to reproduce

Proposed resolution

If there is no status_messages render element present on a page then create one fallback element using Javascript to prevent JavaScript errors.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.3

Component
Javascript 

Last updated 3 days ago

Created by

🇺🇸United States bnjmnm Ann Arbor, MI

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024