Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer crash during destroy() of MultiRootEditor or InlineEditor when the editable was detached manually before destroying. #17684

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Mati365
Copy link
Member

@Mati365 Mati365 commented Dec 23, 2024

Suggested merge commit message (convention)

Fix (editor-inline, editor-multi-root): No longer crash the editor during destroy() when the editable was manually detached before destroying. Closes #16561


Additional information

Some editor types check if elements exist before destroying, while others don't. Here's what works correctly:

https://github.com/ckeditor/ckeditor5/blob/ck/16561/packages/ckeditor5-editor-classic/src/classiceditorui.ts#L141-L143
https://github.com/ckeditor/ckeditor5/blob/ck/16561/packages/ckeditor5-editor-balloon/src/ballooneditorui.ts#L102-L104
https://github.com/ckeditor/ckeditor5/blob/ck/16561/packages/ckeditor5-editor-decoupled/src/decouplededitorui.ts#L96-L98

These editors don't have the checks yet:

https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-editor-inline/src/inlineeditorui.ts#L117-L119
https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-editor-multi-root/src/multirooteditorui.ts#L162-L164

This PR adds missing checks to fix crashes in React integration shown here:

  1. https://github.com/ckeditor/ckeditor5-react/blob/474c8aa9c222b61ed86dad329e05beb92ede29a8/src/useMultiRootEditor.tsx#L64-L88
  2. View#detachDomRoot() might operate on non-existing DOM element #16561

tl;dr React integration removes editables from DOM just before destroying the editor in Strict Mode. This was causing the multiroot editor to crash.

…tor` when the editable was detached manually before destroying.
@pomek
Copy link
Member

pomek commented Dec 23, 2024

AFAIR, there was also a case where somebody called #destroy() twice, and it was also thrown. Could we check if before and after your changes it is valid? If so, I'd add one more test.

As for me, LGTM, but somebody from the Core team should accept it before merging. I am not too familiar with the editor's internals.

@Mati365
Copy link
Member Author

Mati365 commented Dec 23, 2024

Sure thing, I'll take a look.

@Mati365
Copy link
Member Author

Mati365 commented Dec 23, 2024

@pomek

AFAIR, there was also a case where somebody called #destroy() twice, and it was also thrown. Could we check if before and after your changes it is valid? If so, I'd add one more test.

Confirmed, the exception was thrown in inline editor and multi root editor. So it looks like this one fix solved two independent React issues (that one with multiroots and the other in the builder).

I added tests 69533b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View#detachDomRoot() might operate on non-existing DOM element
2 participants