Skip to content

Check if editor is still mounted before trying to focus #5916

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

Merged
merged 2 commits into from
Jul 10, 2025

Conversation

delijah
Copy link
Contributor

@delijah delijah commented Jul 8, 2025

Description
The DOMEditor.focus method has a retry mechanism built in. It can happen, that while retrying to focus the dom node of the editor, meanwhile the editor has been unmounted, which will result in an error when calling DOMEditor.toDOMNode(editor, editor).

This PR adds a check on top of the DOMEditor.focus method, to check if the editor is still mounted, if not return and do not retry to focus the editor dom node anymore.

Issue
Fixes: #5915

Context
This error happened in our unit tests. I guess it's hard to reconstruct in the browser, since it is happening in the milliseconds area.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

Copy link

changeset-bot bot commented Jul 8, 2025

🦋 Changeset detected

Latest commit: d0c535a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-dom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dylans dylans merged commit f2ea1e1 into ianstormtaylor:main Jul 10, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Jul 10, 2025
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.

focus() throws error after editor has been unmounted
2 participants