Problem/Motivation

The solution for this issue #2561619: Drupal Ajax objects and settings grows endlessly lead previously to errors in contrib modules like the one we fixed here #2673824: Views JS passing wrong type of object to Drupal.ajax.
But due to other possible errors in contrib that issue was rolled back in 8.0.x, but I found a related error that breaks in 8.1.x due to that change, you can see it here: https://github.com/dpi/courier/issues/21 maybe in other modules.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Files: 

Comments

edurenye created an issue. See original summary.

edurenye’s picture

Status: Active » Needs review
FileSize
476 bytes

This seems to fix the issue, and I tested a bit and does not seem to break anything else.

edurenye’s picture

droplet’s picture

We may consider checking it explicitly to add support of jQuery object also. It's better backward supports for wrong usages.

droplet’s picture

Priority: Normal » Major

I raised it to Major as it's close to D8.1 release day. We may hit many similar wrong usages.

nod_’s picture

Status: Needs review » Needs work

I don't want to add support for a jQuery object here, the Drupal API should not expect a jQuery object to be passed around. We could add code detecting a jQuery object, to be able to throw an error saying that it's not allowed. Like what we did for Drupal.ajax(). It's already like this for attach functions.

Cross post from #2706577: Non-HTMLElement values for ajax.element cause AJAX errors:

Our docs are pretty clear: ajax.element should be a HTMLElement, which inherits from Element which inherits from Node.

droplet’s picture

Version: 8.1.x-dev » 8.2.x-dev
Assigned: edurenye » Unassigned
Status: Needs work » Needs review
Issue tags: +JavaScript
FileSize
698 bytes

1. throw an error for DX.
2. Skipped in return also.

Needs manual testing before backport to D8.1.x. (A bit confusing at the time, some scripts may missing in D8.1.x)

dpi’s picture

This no longer affects Courier because I am removing the JQ usage. I believe I used jQuery there because I got the impression I had to from the Drupal.ajax documentation:

element: $(context).find('.someElement')

I dont know if this is actually misleading... I know enough JS to be dangerous.

Re the patch from #7:

if (instance && !(instance.element instanceof HTMLElement)) {

Sometimes second condition is failing because instance.element is false.. needs to check for isset?

worldlinemine’s picture

I tested the change in Drupal 8.1.0 manually (not running the patch) and it resolved issue with ajax.js where trying to change the selection of a dropdown for choosing a widget in Content Type spun endlessly.

How does one go about insuring that an updated patch is in place for 8.1.1?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sumanthkumarc’s picture

I'm having a similar error when using modal api of core. I'm using nodejs integration and error comes on ajax call.

Similar issue raised in node js issue queue. Link: https://www.drupal.org/node/2828066

Also, the above patch throws the following error with node js contrib module enabled.

"Uncaught Error: TypeError: instance.element is not a HTMLElement"

Update: The issue got resolved if i disable the Node Js Ajax Framework integration module.

cilefen’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.