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

Invalid selection leads to uncatchable error: "Cannot resolve a DOM point from Slate point" #4643

Open
ricardo opened this issue Nov 4, 2021 · 3 comments · May be fixed by #5407
Open

Invalid selection leads to uncatchable error: "Cannot resolve a DOM point from Slate point" #4643

ricardo opened this issue Nov 4, 2021 · 3 comments · May be fixed by #5407

Comments

@ricardo
Copy link

ricardo commented Nov 4, 2021

Problem
When dealing with complex replacements and selection operations, it's very common to get invalid ranges, which cause the editor to crash with an error Cannot resolve a DOM point from Slate point.

Example code:

// Provide an invalid selection as the second argument.
Transforms.select(editor, { anchor: { path: [55,0] offset: 0 }, focus: { path: [55,0], offset: 10 } } );

I know this would be partially the fault of an unreliable editor built on top of Slate, which could result in such invalid ranges, but I believe Slate could provide better ways to deal with these invalid ranges.

Solution
Suggested approaches:

  • Throw a console.warn warning if the selection is invalid, and do nothing with the command. E.g if it's a select operation, don't perform the operation and throw a descriptive warning.
  • Make the existing error easily catchable within a try/catch block.

Alternatives
Given Slate is still in beta, and there are some open issues around inconsistencies in ranges selecion/removal, I'd say the first option under the proposed solutions would be best - doing nothing in case there's an invalid range and throw a descriptive warning.

@schnuderl
Copy link

also replacing with a different document (for example resetting to original one in a viewmodel) can result quite easily in an invalid selection, resulting in the above exception.

@ahoisl
Copy link
Contributor

ahoisl commented Dec 9, 2021

also replacing with a different document (for example resetting to original one in a viewmodel) can result quite easily in an invalid selection, resulting in the above exception.

We are also running into this problem a lot, especially now that you cannot set the editor value, but have to fallback to remove/add all nodes again when you want to re-initialize an editor

@ahoisl
Copy link
Contributor

ahoisl commented Dec 13, 2021

I believe this is a duplicate of #3641

@zbeyens zbeyens linked a pull request Apr 27, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants