Exceptions thrown when toggling Advanced section of linking form

Created on 30 June 2023, over 1 year ago

Problem/Motivation

When opening the "Advanced" section of the linking form the following error message is displayed in the browser's console window:

Uncaught CKEditorError: collection-add-item-already-exists
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-collection-add-item-already-exists
    at l._getItemIdBeforeAdding (ckeditor5-dll.js?v=38.0.1:5:576882)
    at l.addMany (ckeditor5-dll.js?v=38.0.1:5:574516)
    at l.add (ckeditor5-dll.js?v=38.0.1:5:574323)
    at editorAdvancedLink.js?v=10.1.0:1:9328
    at Array.forEach (<anonymous>)
    at m.onToggle (editorAdvancedLink.js?v=10.1.0:1:9291)

When collapsing the section, this error message appears:

Uncaught CKEditorError: collection-remove-404
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-collection-remove-404
    at l._remove (ckeditor5-dll.js?v=38.0.1:5:577232)
    at l.remove (ckeditor5-dll.js?v=38.0.1:5:575091)
    at l.remove (ckeditor5-dll.js?v=38.0.1:5:440342)
    at editorAdvancedLink.js?v=10.1.0:1:9469
    at Array.forEach (<anonymous>)
    at m.onToggle (editorAdvancedLink.js?v=10.1.0:1:9432)

Steps to reproduce

  1. select a phrase in the ckeditor5 window
  2. click the Link button
  3. click to open the Advanced accordion
  4. view the exception trace stack in the browser's console window
  5. click to close the Advanced accordion
  6. view the exception trace stack in the browser's console window

Proposed resolution

Determine and resolve the cause of the exceptions.

๐Ÿ› Bug report
Status

Active

Version

2.2

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States bkline Virginia

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

Merge Requests

Comments & Activities

  • Issue created by @bkline
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada occupant Canada

    I'm also seeing this using 2.2.4.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States alison

    Apologies if this is an unrelated issue, no scope-creep intended -- and if that's the case, I'll open a new issue -- it just "felt related" --

    I'm getting Uncaught CKEditorError: collection-add-item-invalid-index any time I try to add a link in CKEditor 5, in a text format with "Limit allowed HTML tags and correct faulty HTML" enabled -- do y'all only have the issue you're seeing in text formats with "limited allowed HTML" enabled, or also in a text format that allows all HTML tags?

    More about me:

    • Drupal core 9.5.10
    • Linkit 6.0.0 -- I did try disabling Linkit, the errors still happened
    • Editor Advanced Link 2.2.4 -- then I tried disabling Editor Advanced link, errors went away (and linkit worked fine)

    More error stuff:

    Uncaught CKEditorError: collection-add-item-invalid-index           ckeditor5-dll.js?v=35.4.0
    
    Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-collection-add-item-invalid-index
        at i.addMany (ckeditor5-dll.js?v=35.4.0:5:525625)
        at i.add (ckeditor5-dll.js?v=35.4.0:5:525522)
        at editorAdvancedLink.js?v=9.5.10:1:11273
        at Array.forEach (<anonymous>)
        at h._addGroupsToFormView (editorAdvancedLink.js?v=9.5.10:1:11167)
        at Ke.<anonymous> (editorAdvancedLink.js?v=9.5.10:1:10076)
        at Ke.fire (ckeditor5-dll.js?v=35.4.0:5:502334)
        at Ke.set [as visibleView] (ckeditor5-dll.js?v=35.4.0:5:508922)
        at Ke._showView (ckeditor5-dll.js?v=35.4.0:5:462705)
        at Ke.add (ckeditor5-dll.js?v=35.4.0:5:460104)
    
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    CKEditor 5 docs say:

    The index passed to Collection#addMany() is invalid. It must be a number between 0 and the collection's length.

    โ€” https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#erro...

    And

        at editorAdvancedLink.js?v=9.5.10:1:11273
    

    proves it's triggered by this module.

    @alison Can you confirm you're on https://www.drupal.org/project/editor_advanced_link/releases/2.2.4 โ†’ ?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States alison

    @Wim Leers Yeppers!

    • Drupal core 9.5.10
    • Editor Advanced Link 2.2.4
    • (Also in the mix: Linkit 6.0.0 -- I did try disabling Linkit, the errors still happened; only thing that cleared the errors is disabling editor_advanced_link functionality on that text format.)

    Do you / do y'all think it's noteworthy that the errors only happen on a text format with "limit allow HTML tags" enabled? -- I did try adding stuff to the allowed tags list (by way of "source editing" > "allowed tags" list), but I still got errors. But maybe (hopefully?) I just didn't add everything it needs? (meaning, maybe the EAL module doesn't automagically add all the necessary tags when you enable that button)

    (Attached: filter + editor config yml for my filtered_html text format, in case it's useful.)

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    So we also had the same problem and I found out where the problem lies.

    It has to do with the placement of the confirm and cancel buttons. It's in the file: 'editoradvancedlinkui.js' on line 123 and 124.
    We place the buttons at the end by using '3 + i', but for some reason this is out of bounds for the index CKEditor expects. You can see that because only the confirm button is showing and not the close button. Replacing it to just 'i' places the buttons all the way at the top of de window so that's unwanted. For us making it '2 + i' fixes the error in the console and makes Linkit work again.

    I've added a patch which works for us. But a better solution would be to check how many children are currently active and place it after that. I don't have enough experience with this code nor CKEditor to find out how to do so. But I hope what I found helps with finding a proper solution.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Composer require-dev failure
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    Here is also a patch where it is '1 + i'. As on a different server '2 + i' doesn't solve it but making it 1 does.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    We noticed that some users still had issues with this, so I started testing some more. I noticed that when I removed the entire logic for the buttons, they still stay at the bottom and do not give me any errors.

    I added a new patch, but it will need plenty of testing it seems.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smokris Athens, Ohio, USA

    On a site running Drupal Core 10.1.2, here's what I see with Arantxio's patches:

    If I understand correctly, we want to re-add the "save" and "cancel" buttons to the end of the panel, so they remain in their usual positions. I think we can do that by calling .add(item) (without the index argument). I've attached a new patch that does that.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands gaele

    I tried patch #9. It works, mostly. When I click Advanced I get this message, once:
    Uncaught CKEditorError: collection-add-item-already-exists
    The UI seems to work correctly, though.

  • First commit to issue fork.
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia GuillaumeG

    Same behavior as @gaele ๐Ÿ› Exceptions thrown when toggling Advanced section of linking form RTBC

    The patch #9 ๐Ÿ› Exceptions thrown when toggling Advanced section of linking form RTBC helps to fix the layout and when clicking advanced for the first time but this error is still thrown when clicking on Advanced multiple times.

  • First commit to issue fork.
  • Status changed to Needs review about 1 year ago
  • Testes the patch in #8 and #9 and both of them don't fix all issues here. I pushed a more complete fix based on the patch from #8 for it into an MR. Please review and if you do, continue development inside the MR.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia GuillaumeG

    Thanks @s_leu.

    Patch tested. It is looking good now, no more errors.

  • Status changed to RTBC 12 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia GuillaumeG
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom nicrodgers Monmouthshire, UK

    Hi @GuillaumeG - just to double check - have you tested the patch or the MR?

    Only s_leu said he's continued the work in the MR, but you then say you have tested the patch. Just to be sure. Thanks!

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonnyhocks

    I've moved this back to needs work as I think it still requires some development within the MR.

    I tested the MR and was still seeing the issues described in #9 with the layout of the buttons incorrect. And then when testing the patch in #9 I found the buttons to be laid out correctly.

    Also, I've done some testing in Firefox and I'm not seeing the behaviour described in #10. I have:

    • Added a link
    • Saved the node
    • Edited the node and clicked on the edit link

    I see the 'Advanced' label working as expected.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance duaelfr Montpellier, France

    Hi! FWIW when I first tried to fix that issue, I realized that the buttons behavior was different given the allowed advanced settings selected in the filter. Take that into account when testing your changes because it could work for your specific case but break another oneโ€ฆ I'll be happy to merge a change working for all use cases!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States DamienMcKenna NH, USA

    DuaelFR: do you know which options change the behaviour? We could update the tests to match.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jennypanighetti

    When I apply the patch from the MR#14, I get the buttons both times I try to add a link and no JS errors (progress!) but the "X" button is now below the "Advanced" toggle.

    - Drupal 10.2.2
    - CKEditor 5

  • ๐Ÿ‡ช๐Ÿ‡ธSpain juandels3 Seville

    Hi! After applying patch #14 the display errors are fixed, but errors are still displayed when opening the "Advanced" spoiler. I have made several tests until I detected that this error is only displayed when enabling the "Open in new window ()" attribute in the settings (Text formats and editors > CKEditor 5 plugin settings > Advanced links). If this attribute is disabled, it is not displayed.

  • Status changed to RTBC 10 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    MR17 works on D10.2.3 php 8.2
    no exception, popup displays all buttons and options as expected
    before patch: exceptions in console

    after patch: all clear

    thanks for the patch!
    please release!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohit_aghera Rajkot

    I can confirm that MR #17 works for me as well.
    Drupal core 10.1.x and editor_advanced_link: 2.2.4

    I noticed the same observations mentionedin #25

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jennypanighetti

    Weird, my output still shows the element in between the two elements on the page. See attached screenshot. I am applying the patch via composer.patches.json using the following link: https://git.drupalcode.org/project/editor_advanced_link/-/merge_requests...

  • Status changed to Needs work 9 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    Neither of the MRs are working on: Drupal 10.2.3/PHP8.2
    Editor Advanced Link config: ONLY class attribute enabled

    MR14 - broken layout, console errors

    MR17 - broken layout, console errors

    Editor Advanced Link config: ALL attributes are enabled
    MR14 - doesn't have full keyboard navigation (can't navigate with keyboard inside details element)

    MR17 - console errors, order of fields is invalid

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada bensti

    any update on this issue?

  • Mark Shi โ†’ changed the visibility of the branch 3371633-exception-collection-item-exists to hidden.

  • Mark Shi โ†’ changed the visibility of the branch 3371633-exception-collection-item-exists to active.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom altcom_neil

    Hi,

    Drupal 10.3.5 | Editor Advanced Link 2.2.6 | CKEditor 5

    Is this issue now fixed in the contrib module? We were using patch #9 which was causing js errors now. I have tried both MR14 and MR17 and both have the issues.

    MR14 - correctly lays everything out but has console errors.

    MR17 - leaves the 'Open in a new window' option outside of the Advanced tab.

    I removed the patches and the functionality appears to work without any issues.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain juandels3 Seville

    Hi. The current status is as follows:
    The errors still persists, including in version 2.2.6 with Drupal 10.3.x.

    • Js error when opening the โ€˜Advancedโ€™ tab when more than one attribute has been enabled from the configuration.
    • Js error if a single attribute is enabled from the configuration.
    • MR #17 fixes the first point, but takes the โ€˜Open in new windowโ€™ value out of โ€˜Advancedโ€™.
  • Hi,

    Drupal 10.3.9 and editor advanced link 2.2.6, same behavior described in #33.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada metasim

    Using MR 17 as patch for version 2.2.6
    - the console error goes away
    - `open in new window` option is still available

Production build 0.71.5 2024