JS-Error when used in "non-expanded" area (Paragraphs)

Created on 29 October 2021, about 3 years ago
Updated 30 March 2023, over 1 year ago

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

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany sascha_meissner Planet earth

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024