Problem/Motivation
Console error on node edit form:
TypeError: Cannot read properties of undefined (reading 'querySelector')
Steps to reproduce
- Create a node that has a paragraph entity reference field, referring to the layout_paragraphs paragraph
- Insert content for a single row
- Try to move the content via drag/drop
- Observe the error in the console
- Also notice that you cannot "drop" the selected element
Please note that this also occurs once saved and then trying to edit the layout paragraph again.
Proposed resolution
Add extra conditions to updateMoveButtons() in builder.js
Before
(_components$0$querySe = components[0].querySelector('.lpb-up')) === null || _components$0$querySe === void 0 || _components$0$querySe.setAttribute('tabindex', '-1');
(_components$querySele = components[components.length - 1].querySelector('.lpb-down')) === null || _components$querySele === void 0 || _components$querySele.setAttribute('tabindex', '-1');
After
(_components$0$querySe = components[0] && components[0].querySelector('.lpb-up')) === null || _components$0$querySe === void 0 || _components$0$querySe.setAttribute('tabindex', '-1');
(_components$querySele = components[components.length - 1] && components[components.length - 1].querySelector('.lpb-down')) === null || _components$querySele === void 0 || _components$querySele.setAttribute('tabindex', '-1');
Alternatively, look into updating move buttons, only if there are multiple elements?
Comments
Comment #2
mistrytheory commentedComment #3
mistrytheory commentedPatch based on proposed solution.
Comment #4
mistrytheory commentedUpdated patch that actually works
Comment #6
sethhill commentedI haven't been able to replicate this error on 2.0.8 or the latest 2.0.x branch. Can you provide more information on your configuration?
Comment #7
ckngJust ran into exactly same issue. Tested patch #4, working for us.
Having the issue on
- core 10.3.2
- LP 2.0.6-2.0.8
Comment #8
ckngComment #9
ckngSorry, didn't mean to change that.
Tested 2.1.0, so far unable to reproduce the issue.
Comment #10
vit.smutny commentedHello, I encountered an issue while using multiple fields directly in a node with Layout Paragraphs in version 2.1.0. If there are multiple fields with Layout Paragraphs in a node, it only works correctly for elements in the first field. In each subsequent field with Layout Paragraphs, it does not function properly.
For me, the fix from patch #4 worked, but only the first part, and not in the file builder.es6.js, but in builder.js.
Comment #11
nicholass@ckng see https://www.drupal.org/project/layout_paragraphs/issues/3476838 for video demo of problem, not sure what exact conditions you have to have for the drag and drop to not work, but its only on some of our content pages not all.
Comment #13
nicholassCreated a patch for 2.1.x branch, patch #4 could not apply for me, so use https://git.drupalcode.org/project/layout_paragraphs/-/merge_requests/18...
Here is a debugger on the issue for those interested
https://www.drupal.org/files/issues/2024-10-03/dragndropjsdebug.mp4
Comment #14
nicholassComment #15
ckngRan into the issue again. Rerolled and rebased to 2.1.x. Generated patch.
Comment #16
hoemmawelt commentedI tested it in a Drupal 11 installation and the error is fixed by the patch #15. The "move up" and "move down" buttons are now removed from the keyboard navigation when only one item is present.
Comment #17
hoemmawelt commentedComment #18
pixelwhip commentedI can also confirm patch #15 fixes this issue for me.
Comment #20
sethhill commentedComment #21
sethhill commentedComment #22
justin2pin commentedComment #25
luisnicg commentedI'm still facing this issue under certain conditions on version 2.1.3 which I describe below:
1. Create a nested paragraph for example an Accordion Item which contain an Entity reference revisions field with more paragraphs
2. The formatter of the field that contains more paragraphs was set to "Layout Paragraph Builder (Experimental)"
3. Create the component parent "Accordion" which contain the Entity reference revisions field to bring the the Accordion Item paragraph.
4. The formatter of this field was set to Rendered Entity
5. Add a content type with the field that include the Accordion and set the widget and formatter as "Layout Paragraph"
Due to this configuration the code in the file builder-form.js is loaded but never find the element.
I added a patch that basically validates if the element exist.
Comment #26
tiago commented@luisnicg, the case from #25 is still there on 3.0.x, so I opened a follow-up with your patch as a merge request against 3.0.x: #3627475: builder-form.js throws when a component event fires outside the builder form.