Slate: Cannot get the start point in the node at path [1] because it has no start text node.

Created on 21 Apr 2020  路  5Comments  路  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Report a bug

What's the current behavior?

Bug GIF:

https://codesandbox.io/s/slate-reproductions-cm3r7?file=/index.js

Slate: 0.57.1
Browser: Chrome
OS: Mac

What's the expected behavior?

The expected behavior is that the string can be parsed to Slate object without throwing an error.


I found that the bug is in this function

https://github.com/ianstormtaylor/slate/blob/f6bfe034d707693488c38da77537fd36cb8856cf/packages/slate-hyperscript/src/creators.ts#L27-L81

because the p tag has no text, the children parameter is an empty array, therefore the for loop is never performed and returns the variable node as an empty array.

Most helpful comment

Hi @lavaldi , the issue is that the paragraph blocks the deserialize function generates are allowed to have no children. This is an invalid state for slate; all blocks need to have at least one text node, even if it is empty. The deserializer function should be updated to correct that issue.

As for images, you should be able to pass a void flag to the image block to indicate that it is not intended to have text children. See the image example for how some examples of void blocks.

All 5 comments

Perhaps a validation should be added that if children is an empty array that it returns [{ text: '' }] 馃

Hi @lavaldi , have you tried <p /> to see if it makes a difference?

(Also, the gif with the minimum reproduction is a bit hard for me to use for helping you so a minimum reproduction in a code sandbox would be cool if that doesn't work)

Thanks!

@DamareYoh there is a link to the codesanbox in the issue description (after the GIF).

Also, the error is thrown with the image tag <img src="[image_url]" />. You can test it in the codesandbox.

Hi @lavaldi , the issue is that the paragraph blocks the deserialize function generates are allowed to have no children. This is an invalid state for slate; all blocks need to have at least one text node, even if it is empty. The deserializer function should be updated to correct that issue.

As for images, you should be able to pass a void flag to the image block to indicate that it is not intended to have text children. See the image example for how some examples of void blocks.

I see, thank you for your help 馃憤

Was this page helpful?
0 / 5 - 0 ratings