Problem/Motivation
@file entity_browser.table.js there is a line of vanilla-js on top of the drupal-behaviour definition that fails with "Error querySelector on null" and causes weird following errors to the ajax-requests of that particular entity-browser. We tried to find out why it even exists outside of the drupal-behaviour, everything works fine without this line.
Steps to reproduce
Create a paragraph_type with a reference field and entity_browser_table as form-display, now when you have an entity with a reference to paragraphs, the added paragraph_type is initially not expanded and does not contain the dom that the executed line of js expects, the code inside the drupal-behaviour that uses $(context) is fine and does what it should without failing.
(Might not only affect paragraph_types but every kind of form-implementation where the .table--widget-entity_reference_browser_table_widget is inserted after this script executes)
/**
* @file entity_browser.table.js
*
* Allows the table rows to be sortable.
*/
(function ($, Drupal) {
'use strict';
// The line below this comment will fail with "Error querySelector on null" because the DOM doesnΒ΄t exist
document.querySelector('.table--widget-entity_reference_browser_table_widget').querySelector('tbody').classList += ' entities-list sortable ui-sortable';
Drupal.behaviors.entityBrowserEntityReferenceTable = {
...
The error causes weird following behaviour to Ajax-Requests from that EB
Proposed resolution
We just removed this line and everything works.
Another option would be to just check if `'.table--widget-entity_reference_browser_table_widget'` exists before calling querySelector on it