ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.89k stars 3.25k forks source link

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

Open ricardo opened 3 years ago

ricardo commented 3 years ago

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:

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I believe this is a duplicate of #3641