Description
Description
Whenever the first item in a document's children is a non-leaf node (i.e. a list), it throws Cannot get the leaf node at path [0,0] because it refers to a non-leaf node.
and crashes.
Example
Here is a note who's only children (and thus it's first content) is a list Element. Here's what my Custom children schema looks like:
"children": [
{
"type": "numbered-list",
"children": [
{
"type": "list-item",
"children": [
{
"type": "text",
"children": null,
"text": "",
"url": null
}
],
"text": null,
"url": null
},
{
"type": "list-item",
"children": [
{
"type": "text",
"children": null,
"text": "",
"url": null
}
],
"text": null,
"url": null
}
],
"text": null,
"url": null
}
],
And then when reloading the note
Sandbox
https://codesandbox.io/p/sandbox/slate-reproductions-forked-93p6g9
Steps
To reproduce the behavior:
- Go to the sandbox
- Try switching from the first note to the second, and vice versa. This should work.
- Go back to the first note.
- Make sure you're focused on the textbox, and click "Turn line to list"
- Switch to the second note, then back to the first
- Get an error: Cannot find a descendant at path [0,0,0].
Now this error is different than the one I get in my own project, but the error is caused by attempting to read marks, as removing isMarksActive from use prevents the error from being thrown. I commented out isMarksActive in my own project, and it fixed the issue as well, so both problems are linked to this function. In my own personal case, I only get this error when a non-leaf element is the first element in a note's content.
Expectation
It should render and work despite an element being a block.
Environment
- Slate Version: 0.112
- Operating System: Windows
- Browser: Native WebView (Tauri V2)
Context
I assume this would be fixed by verifying first if the element we're checking for marks is a leaf, however I'm not sure how to do that and maybe there's a better way.