ianstormtaylor / slate

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

Cannot resolve a Slate point from DOM point: [object Text],0 #3834

Open silviubogan opened 4 years ago

silviubogan commented 4 years ago

Do you want to request a feature or report a bug?

Bug.

What's the current behavior?

On page load, ReactEditor.toSlateRange calls ReactEditor.toSlatePoint which throws an exception because ReactEditor.toSlatePoint does not find a valid textNode through the algorithm inside it. I do not know how to make sure this is not the same issue as https://github.com/ianstormtaylor/slate/issues/3421. The steps to reproduce are many, but if there is interest I will write them, at least so I can get help.

The starting piece of code is taken from here (yes, it is a hack to solve another Slate issue temporarily):

if (!editor.selection) {
  const sel = window.getSelection();

  if (sel && sel.rangeCount > 0) {
    debugger;
    const s = ReactEditor.toSlateRange(editor, sel);
    // Maybe do a comparison of s with editor.selection through Range.equals
    // before giving a new reference to the editor.selection?
    editor.selection = s;
  }
}

So, everything begins with this call from the above written code:

ReactEditor.toSlateRange(editor, sel);

Before this call:

Screenshot_20200819_163949

Screenshot_20200819_162532

These are the relevant parts of the code as I was debugging:

Screenshot_20200819_162806

Screenshot_20200819_163001

The final error visible to the user is Cannot resolve a Slate point from DOM point: [object Text],0.

The sandbox

It is here but:

Then and only then we can see the bug appear in the sandbox.

Slate: 0.58.3 Browser: Chromium 84.0.4147.125 (official version) Arch Linux (64bit) OS: Linux (Manjaro)

What's the expected behavior?

No error, no exception, the page should load well and display the editor waiting for the user to write in it.

Thank you.

MangoIsGreat commented 6 months ago

I have the same problem,how to solve it?