question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Cannot resolve a Slate point from DOM point" for non-editable text rendered inside of Element

See original GitHub issue

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

Bug

What’s the current behavior?

When selecting (supposed to be) non-editable text that is rendered inside of an element, I am seeing an error “Cannot resolve a Slate point from DOM point”. My usecase is to have a prefix that isn’t editable, but explains the purpose of the block.

Slate: 0.57.1 Browser: Chrome 79.0.3945.117 OS: MacOS 10.15.2 (19C57)

Large GIF (996x358)

Edit React Slate

VM469:1691 Uncaught Error: Cannot resolve a Slate point from DOM point: [object Text],7
    at Object.toSlatePoint (eval at Dr (eval.js:61), <anonymous>:1691:13)
    at Object.toSlateRange (eval at Dr (eval.js:61), <anonymous>:1736:30)
    at HTMLDocument.eval (eval at Dr (eval.js:61), <anonymous>:800:43)
    at later (eval at Dr (eval.js:61), <anonymous>:27:23)
toSlatePoint @ VM469:1691
toSlateRange @ VM469:1736
eval @ VM469:800
later @ VM474:27
setTimeout (async)
later @ VM474:23
setTimeout (async)
later @ VM474:23
setTimeout (async)
later @ VM474:23
setTimeout (async)
debounced @ VM474:38

What’s the expected behavior?

To see no error, and have Slate ignore the non-editable text.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
hcharleycommented, Jan 11, 2020

This is kind of strange, but I think a hack solution is to use both a CSS style and an HTML attribute.

✅ For example, this works to render elements:

<div {...attributes}>
  <div
    style={{ userSelect: "none" }}
    contentEditable={false}
  >
    Non-editable
  </div>
  <p>{children}</p>
</div>

🛑 But oddly, this doesn’t work:

<div {...attributes}>
  <div
    contentEditable={false}
  >
    Non-editable
  </div>
  <p>{children}</p>
</div>

🛑 Nor does this:

<div {...attributes}>
  <div
    style={{ userSelect: "none" }}
  >
    Non-editable
  </div>
  <p>{children}</p>
</div>

I added these examples to the example code sandbox above.

I say this is a “hack solution” because ideally all you would need is contentEditable={false} to avoid this problem. An example usecase for this: you might want to let users select this non-editable text, and userSelect: none CSS prevents that.

NOTE: This does not seem to stop the error from happening when doubleclicking into a child, and selecting all of the text. It seems to sometimes stop it, but not always. This specifically stops the error from happening when selecting or clicking on the non-interactive text specfically.

24reactions
dark-swordsmancommented, Feb 25, 2022

I ran into this problem when rendering nothing in the slate component, since the introduction tutorial starts off with nothing in the useState([]). So I guess it tries to render an empty array, but has nothing to put the values into at the start.

To solve this, I set this as the default value:

  const [value, setValue] = useState<Descendant[]>([
    {
      type: "paragraph",
      children: [{ text: "" }],
    },
  ]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot resolve a DOM point from Slate point
In my case, I was taking a populated editor with a bunch of text and tried to reset it back to it's original...
Read more >
"Cannot resolve a Slate point from DOM point" for non ...
What's the current behavior? When selecting (supposed to be) non-editable text that is rendered inside of an element, I am seeing an error...
Read more >
Newest 'slatejs' Questions - Stack Overflow
Slate React: cannot redefine element's text. I use Slate editor in my React app. I've created the custom inline tool called 'company'. Once...
Read more >
Slate Editor Issue: Cannot resolve a DOM point from ... - Reddit
This is the code I am using to add my custom link DOM element into slate editor at current cursor position. window.addEventListener("message", ( ......
Read more >
Slate React
React components for rendering Slate editors ... Get the current readOnly state of the editor. ... Find a native DOM selection point from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found