Can't access property "command", _response$key is null

Created on 15 June 2023, over 1 year ago
Updated 10 April 2024, 8 months ago

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;
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Ajax 

Last updated about 1 hour ago

Created by

🇷🇺Russia kvantstudio

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @kvantstudio
  • First commit to issue fork.
  • Status changed to Needs review 8 months ago
  • 🇮🇳India Aadhar_Gupta

    In the modification, I added a check for null or undefined values when accessing properties of the response object using response[key] || {}. 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.

  • Pipeline finished with Failed
    8 months ago
    Total: 990s
    #142391
  • Status changed to Needs work 8 months ago
  • 🇺🇸United States smustgrave

    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.

Production build 0.71.5 2024