Exceptions in batch no longer are shown on the page: Javascript error

Created on 6 December 2023, 10 months ago
Updated 8 December 2023, 10 months ago

Problem/Motivation

Splitting this from 🐛 Exceptions in batch no longer are shown on the page when Javascript is disabled Needs work because there are actually 2 reasons why this happens. Once if you have Javascript enabled and one if you do not.

Obviously most users will have JS enabled but the non-JS version is still important because it means you can't test this without being a JS tests.

@bnjmnm comment on #3392196-21: Exceptions in batch no longer are shown on the page when Javascript is disabled

Info on the FunctionalJavaScript test failure:

  • The test failure is in fact due to a change introduced [##2987444]
  • Prior to that change, AJAX errors were only reported in the JS console. Nothing reported in the Drupal UI. This was addressed by adding core/drupal.message as a dependency to core/drupal.ajax
  • Apparently core/drupal.message assumes theres a '#type' => 'status_messages' render element on the page. \Drupal\Tests\system\FunctionalJavascript\Batch\ProcessingTest is failing because it expects the markup that would be provided by the status_messages render element.

Clearly something needs to be addressed in core/drupal.message since JS since JS libraries can't declare dependencies on render elements. It's safe to say that isn't something that needs to be addressed in this issue's scope. Adding a '#type' => 'status_messages' element to the test page should get the FJS test working, and the underlying issue has its own issue now 🐛 The core/drupal.message library requires a status_messages render element Active

Steps to reproduce

Proposed resolution

Use the approach in 3406612-use-messages-theme merge request

In \Drupal\system\Controller\BatchController::batchPage simply add

// Directly render a status message placeholder without any messages.
      // Messages are not intended to be show on the batch page, but in the event
      // an error in a AJAX callback the messages will be displayed.
      $output['batch_messages'] = [
        '#theme' => 'status_messages',
        '#message_list' => [],
        '#status_headings' => [
          'status' => t('Status message'),
          'error' => t('Error message'),
          'warning' => t('Warning message'),
        ],
      ];

This intentionally does not use '#type' => 'status_messages', which automatically render the server side messages which is not expected behavior on the batch page.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.2

Component
Ajax 

Last updated 2 days ago

Created by

🇺🇸United States tedbow Ithaca, NY, USA

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