Cannot replace 'Displayed text' of existing links

Created on 10 July 2025, about 1 month ago

Problem/motivation

During our testing for the upgrade to Drupal 10.5.x, we identified a bug that occurs when attempting to update the "Displayed text" of an existing link.

Drupal 10.5.1
Linkit 7.0.6
Uncaught CKEditorError: Cannot read properties of undefined (reading 'attributes')
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-Cannot read properties of undefined (reading 'attributes')
    at mi.getChanges (ckeditor5-dll.js?v=45.2.0:5:428639)
    at html-support.js?v=45.2.0:5:29843
    at vi._callPostFixers (ckeditor5-dll.js?v=45.2.0:5:442557)
    at vi._handleChangeBlock (ckeditor5-dll.js?v=45.2.0:5:441779)
    at qi._runPendingChanges (ckeditor5-dll.js?v=45.2.0:5:476270)
    at qi.change (ckeditor5-dll.js?v=45.2.0:5:473265)
    at _.<anonymous> (editorAdvancedLink.js?v=10.5.1:1:2664)
    at _.fire (ckeditor5-dll.js?v=45.2.0:5:639290)
    at <computed> [as execute] (ckeditor5-dll.js?v=45.2.0:5:642831)
    at f.execute (ckeditor5-dll.js?v=45.2.0:5:163419)
ckeditor5-dll.js?v=45.2.0:5 Uncaught CKEditorError: document-selection-wrong-position {"range":{"start":{"root":"main","path":[0,9],"stickiness":"toNone"},"end":{"root":"main","path":[0,9],"stickiness":"toNone"}}}
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-document-selection-wrong-position
    at Co._validateSelectionRanges (ckeditor5-dll.js?v=45.2.0:5:329930)
    at Co._replaceAllRanges (ckeditor5-dll.js?v=45.2.0:5:329670)
    at Co._setRanges (ckeditor5-dll.js?v=45.2.0:5:320078)
    at Co.setTo (ckeditor5-dll.js?v=45.2.0:5:319218)
    at Co.setTo (ckeditor5-dll.js?v=45.2.0:5:328804)
    at Ao._setTo (ckeditor5-dll.js?v=45.2.0:5:326266)
    at Pi.setSelection (ckeditor5-dll.js?v=45.2.0:5:455870)
    at Object.callback (ckeditor5-dll.js?v=45.2.0:5:356853)
    at qi._runPendingChanges (ckeditor5-dll.js?v=45.2.0:5:476216)
    at qi.change (ckeditor5-dll.js?v=45.2.0:5:473265)

Steps to reproduce

While I haven’t been able to reproduce the issue consistently, I can trigger the error approximately 90% of the time. Given this frequency, I believe it's worth creating an issue for further discussion and investigation.

  1. Edit an existing link
  2. Try to update the 'Displayed text'

P.S. It seems that appending text doesn’t trigger the error, but replacing the entire text does make it more likely to occur.

πŸ› Bug report
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡ΉπŸ‡ΌTaiwan peterwcm

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

Merge Requests

Comments & Activities

  • Issue created by @peterwcm
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this. I am able to reproduce. Specifically, using a generic installation of the Standard profile, adding Linkit to the Basic HTML text format:

    1. Click the "Link" icon.
    2. Enter a "Displayed text" value.
    3. Enter the first character of an existing node and use Linkit's autocomplete to choose a result from the dropdown. Confirm that the internal path to the node is populated in the "Link URL" field.
    4. Quickly(!) Remove the contents from the "Displayed text" input and quickly enter new text and press "Insert."
    5. Link text will not be updated and the console will show the Uncaught CKEditorError: Cannot read properties of undefined (reading 'attributes') error.

    Additionally, this is something else that doesn't work correctly.
    1. Click the "Link" icon.
    2. Enter a "Displayed text" value.
    3. Enter the first character of an existing node and use Linkit's autocomplete to choose a result from the dropdown. Confirm that the internal path to the node is populated in the "Link URL" field.
    4. Now click "Link URL" field again and enter the first character of another node and use Linkit's autocomplete to choose a different result.
    5. The link field will NOT correctly populate the internal path to the node but will simply populate the character you entered.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I've merged a number of changes related to CKEditor v45 compatibility to reduce the surface area here. The originally reported problem still remains, so this is "Needs work."

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Also had to disable the "Linkit profile" for Ckeditors after updating core 10.5 due to the error "Cannot convert undefined or null to object" in CKEditor 5 caused by a bug in the Linkit module version 6.1.6. Specifically, in the JavaScript file index.js at line 122, the code attempts to call Object.assign(args[2], values) where args[2] can be undefined or null. This occurs when the CKEditor 5 link command is executed with fewer than 3 arguments, but the code assumes the third argument (index 2) will always be an object.

    When title is empty and clicking insert

  • πŸ‡¦πŸ‡ΊAustralia jannakha Brisbane!

    @nicholass
    when you're updating dependencies, especially when Drupal is updated, run command to check for any major versions of contrib modules:
    composer outdated -M -D

    composer update usually just updates minor version by default (eg 6.1 to 6.2) if dependency has carrot (^) "drupal/linkit": "^6.0", but not to 7.0

  • πŸ‡©πŸ‡ͺGermany mrshowerman Munich

    @mark_fullmer, see my comment in #3534699-14: Refactor plugin for CKEditor5 v45+ β†’ for another bug that is related to CKEditor 45. Not sure if this is the right place to report, but as @jannakha points out in their reply, it likely has to be fixed in Linkit.

    Of course, I can also open a separate issue if that is preferred.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    see my comment in #3534699-14: Refactor plugin for CKEditor5 v45+ for another bug that is related to CKEditor 45...Of course, I can also open a separate issue if that is preferred.

    It appears that another community member created a separate issue for that today: πŸ› Editing Displayed text generates multiple links Active . I think it makes sense to initially keep that issue and this one tracked separately; if the fix ends up fixing both, fine :)

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I've created a new target development branch, 7.1.x, for this work, since it will require introducing backwards-compatibility-breaking changes. See https://www.drupal.org/project/linkit/releases/7.1.x-dev β†’

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡§πŸ‡·Brazil giancarlorosa

    Doing more tests, I found some specific behaviors related to this issue. First, I was using Linkit version 7.0.7, and this issue was happening through internal and external links. Now, I updated to version 7.0.8, and it seems that internal links are working just fine, but for external links, the issue still happens.

    I've noticed that this issue tends to happen when, instead of selecting a text and adding a link, I add the link by directly clicking on the Link button from CKEditor. It's like if the created link does not have a reference to the element and can not update the Displyed text value.

    Here are the steps to reproduce the issue:

    1. Go to any node with CKEditor
    2. Add link by clicking on Link button from CKEditor
    3. In the Link URL field, set to 'www.youtube.com'
    4. The Displayed text field must be empty
    5. Click on insert
    6. Click on the link and edit it
    7. The Displayed text field should have the same value as the Link URL field
    8. Change the Displayed text field
    9. Click on update

    This will generate the following errors on console:

    ckeditor5-dll.js?v=45.2.0:5 Uncaught CKEditorError: Cannot read properties of undefined (reading 'attributes')
    Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-Cannot read properties of undefined (reading 'attributes')
        at mi.getChanges (ckeditor5-dll.js?v=45.2.0:5:428639)
        at html-support.js?v=45.2.0:5:29843
        at vi._callPostFixers (ckeditor5-dll.js?v=45.2.0:5:442557)
        at vi._handleChangeBlock (ckeditor5-dll.js?v=45.2.0:5:441779)
        at qi._runPendingChanges (ckeditor5-dll.js?v=45.2.0:5:476270)
        at qi.change (ckeditor5-dll.js?v=45.2.0:5:473265)
        at Object.<anonymous> (ckeditor5-dll.js?v=45.2.0:5:356839)
        at Object.fire (ckeditor5-dll.js?v=45.2.0:5:639290)
        at fe (ckeditor5-dll.js?v=45.2.0:5:219549)
        at ke.fire (ckeditor5-dll.js?v=45.2.0:5:218940)
    
    Uncaught CKEditorError: document-selection-wrong-position {"range":{"start":{"root":"main","path":[1,18],"stickiness":"toNone"},"end":{"root":"main","path":[1,18],"stickiness":"toNone"}}}
    Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-document-selection-wrong-position
        at Co._validateSelectionRanges (ckeditor5-dll.js?v=45.2.0:5:329930)
        at Co._replaceAllRanges (ckeditor5-dll.js?v=45.2.0:5:329670)
        at Co._setRanges (ckeditor5-dll.js?v=45.2.0:5:320078)
        at Co.setTo (ckeditor5-dll.js?v=45.2.0:5:319218)
        at Co.setTo (ckeditor5-dll.js?v=45.2.0:5:328804)
        at Ao._setTo (ckeditor5-dll.js?v=45.2.0:5:326266)
        at Pi.setSelection (ckeditor5-dll.js?v=45.2.0:5:455870)
        at Object.callback (ckeditor5-dll.js?v=45.2.0:5:356853)
        at qi._runPendingChanges (ckeditor5-dll.js?v=45.2.0:5:476216)
        at qi.change (ckeditor5-dll.js?v=45.2.0:5:473265)
    

    If I execute the same process, but instead of adding a link by first clicking on the Link button, I first select a text inside CKEditor, the Linkit works fine.

  • πŸ‡¦πŸ‡ΊAustralia jannakha Brisbane!

    use 7.0.7 and MR122 from https://www.drupal.org/project/linkit/issues/3535479 πŸ“Œ Refactor Linkit plugin for CKEditor5 v45+ Active (hidden branch)

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    mark_fullmer β†’ changed the visibility of the branch 3535098-ckeditor-v45-cannot to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    mark_fullmer β†’ changed the visibility of the branch 3535098-ckeditor-insert-fix to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I've confirmed that changes staged in the merge request for πŸ› Editing Displayed text generates multiple links Active do resolve this issue's problem, and would love confirmation of that from someone else: using that branch, confirm that the "Steps to Reproduce" from #16 above result in successfully being able to change link text.

    The problem of duplicated links is still present in the merge request for πŸ› Editing Displayed text generates multiple links Active , so I'm continuing to work on that...

  • Merge request !132Resolve #3535098 "Unable update link" β†’ (Open) created by mark_fullmer
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
Production build 0.71.5 2024