Problem/Motivation

Problem in core/misc/ajax.js.

Steps to reproduce

When use response like this:

$response = new AjaxResponse();
$response->setData(['params' => NULL]);
return $response;

We get error: Uncaught TypeError: can't access property "command", _response$key is null

Proposed resolution

We must check _response$key in Drupal.Ajax.prototype.success:

var _response$key = response[key];
var command = _response$key.command ?? null,
     method = _response$key.method ?? null;

Issue fork drupal-3367107

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

kvantstudio created an issue. See original summary.

cilefen’s picture

Issue tags: -ajax error +JavaScript

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Aadhar_Gupta made their first commit to this issue’s fork.

Aadhar_Gupta’s picture

Status: Active » Needs review
Issue tags: -JavaScript +JavaScript

In the modification, I added a check for null or undefined values when accessing properties of the response object. This ensures that if response[key] is null or undefined, an empty object will be used instead, preventing potential errors when trying to access properties of null or undefined values. This modification should help address the issue you're encountering with the AJAX response handling in Drupal.

smustgrave’s picture

Status: Needs review » Needs work

Should do some research and find out why it's null vs just a check.

Could be masking a larger issue if we silence the error. If after the research the fix is still to just put a check that's fine but still need to find out more info.

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.