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

Issue fork drupal-2705327

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

edurenye created an issue. See original summary.

edurenye’s picture

Status: Active » Needs review
StatusFileSize
new476 bytes

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

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
StatusFileSize
new698 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.

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

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

Version: 8.5.x-dev » 8.6.x-dev

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

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

socialnicheguru’s picture

I tried this on Drupal 8.5.8
I got a number of js errors in the console after I enabled agregation.
No errors without aggregation

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

handkerchief’s picture

Any news on this? It would be great if this fix could be integrated into the core.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Hamulus’s picture

Issue tags: -JavaScript +JavaScript

this patch was helpful for me in D9 in 2021

so why don't include it in release?

bnjmnm’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

I notice #19 and #23 both ask why this hasn't been added to Drupal. This is because it's waiting for someone in the community to review it then change the issue status to "Reviewed and Tested by the Community". Anyone that has had this patch work for their site has effectively already performed a manual review. If that is accompanied by a code review - and both the manual and code reviews are documented here - you can switch to "Reviewed and Tested by the Community" and it will move to the next stage of getting into core.

In this case, a bit of work is needed due to the age of the patch. Setting to "needs work" as the patch only alters a .js file, presumably because it was created before Drupal began using .es6.js files that transpile to .js. The change would need to be made in ajax.es6.js, which would then be transpiled to ajax.js

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

abhisekmazumdar’s picture

Status: Needs work » Needs review

Hey, I thought this would be the right time to create an MR for this PR. As this required a re-roll.
Kindly review my MR.

bmunslow’s picture

StatusFileSize
new215.34 KB

Hi,

I reviewed and tested MR by @abhisekmazumdar in #27.

It applies cleanly on D.9.x and it fixes the issue indeed.

My only concern is that this patch produces 25 errors in JS console in pages where there were no errors before the patch.

These errors don't seem to affect any other functionality so far, but they certainly impact negatively the developer's experience.

The errors appear regardless of whether JS aggregation is enabled or not.

Console log errors after ajax patch

bmunslow’s picture

Issue tags: -Needs reroll

So I did further testings and noticed the JS errors I reported about in #28, appeared only if the Big Pipe module was enabled.

I added an additional check: instance.element !== false before throwing Drupal error, this fixes all issues for me:

  • Failed to execute 'contains' on 'Node' issue is gone
  • Enabling Big Pipe doesn't generate any additional JS errors on console

Could someone please review this latest change and report back so we can set this to RTBC?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new149 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.