Skip to content

Fix hasDOMNode throwing error when editor is not mounted#6009

Draft
gbalint wants to merge 1 commit intoianstormtaylor:mainfrom
gbalint:fix/hasdomnode-unmounted-editor
Draft

Fix hasDOMNode throwing error when editor is not mounted#6009
gbalint wants to merge 1 commit intoianstormtaylor:mainfrom
gbalint:fix/hasdomnode-unmounted-editor

Conversation

@gbalint
Copy link

@gbalint gbalint commented Feb 2, 2026

Wrap the toDOMNode call in a try-catch to gracefully handle the case where the editor is not yet mounted. In this case, the target cannot be part of the editor, so returning false is the correct behavior.

Description
A clear and concise description of what this pull request solves. (Please do not just link to a long issue thread. Instead include a clear description here or your pull request will likely not be reviewed as quickly.)

Issue
Fixes: (link to issue)

Example
A GIF or video showing the old and new behaviors after this pull request is merged. Or a code sample showing the usage of a new API. (If you don't include this, your pull request will not be reviewed as quickly, because it's much too hard to figure out exactly what is going wrong, and it makes maintenance much harder.)

Context
If your change is non-trivial, please include a description of how the new logic works, and why you decided to solve it the way you did. (This is incredibly helpful so that reviewers don't have to guess your intentions based on the code, and without it your pull request will likely not be reviewed as quickly.)

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.)

Wrap the toDOMNode call in a try-catch to gracefully handle the case
where the editor is not yet mounted. In this case, the target cannot
be part of the editor, so returning false is the correct behavior.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: c2af4ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@12joan
Copy link
Contributor

12joan commented Feb 2, 2026

My concern is this might risk masking genuine issues. Have you considered introducing a new DOMEditor.isMounted(editor) query that you can use prior to calling hasDOMNode instead? The logic for this could be refactored out of DOMEditor.focus, which is currently using !EDITOR_TO_ELEMENT.get(editor) to determine if we're mounted or not.

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.

2 participants