Skip to content

Editor error due to stale Image .ck-fake-selection-container after clearing and restoring content #18458

@GDDanielCatalinIlie

Description

@GDDanielCatalinIlie

📝 Provide detailed reproduction steps (if any)

  1. Initialize CKEditor 5 (Classic build) with content that includes an inline image.
  2. Add a change listener to sync the editor’s content:
editor.model.document.on('change:data', () => {
    editorElement.value = editor.getData();
});
  1. Select the image so that its toolbar is visible (important: selection must be active).
  2. Call editor.setData('') while the image is still selected.
    (Optional Backup the current content: const data = editor.getData();)
  3. Restore the previous OR set new content: editor.setData(data); (v44)
  4. Select the image again. (v45)

CodePen reproduction (v44.3.0): 👉 CodePen – CKEditor 5 fake-selection issue
To trigger the error:

  • wait for the CodePen page to finish loading
  • select the image so that it's toolbar is displayed
  • click the setData('') button
  • click the restore button

✔️ Expected result

setData() should safely clear and restore content, regardless of the selection state.

Re-selecting an image after restoring content should not throw an error from the editor.

❌ Actual result

v44.3.0: Calling setData(content) immediately after selecting an image and calling setData('') throws an error.

v45.0.0: setData(content) no longer throws, but selecting the image again after content restore causes an error.

In both cases, the .ck-fake-selection-container element may persist and contribute to the broken state.

❓ Possible solution

To avoid this I have to manually remove any .ck-fake-selection-container from the DOM before updating content. This avoids the error but is not an ideal solution.

📃 Other details

  • Browser: Latest Chrome and Firefox
  • OS: macOS, Windows
  • First affected CKEditor version: 44.3.0
  • Installed CKEditor plugins: N/A

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugThis issue reports a buggy (incorrect) behavior.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions