Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get the leaf node at path [0,0] because it refers to a non-leaf node. #5820

Open
CaseSens opened this issue Mar 12, 2025 · 1 comment
Labels

Comments

@CaseSens
Copy link

CaseSens commented Mar 12, 2025

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
    }
  ],

Image

And then when reloading the note

Image

Sandbox
https://codesandbox.io/p/sandbox/slate-reproductions-forked-93p6g9

Steps
To reproduce the behavior:

  1. Go to the sandbox
  2. Try switching from the first note to the second, and vice versa. This should work.
  3. Go back to the first note.
  4. Make sure you're focused on the textbox, and click "Turn line to list"
  5. Switch to the second note, then back to the first
  6. 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.

@CaseSens CaseSens added the bug label Mar 12, 2025
@Sourciluss667
Copy link

Same bug for me, disable autofocus on Slate react Editable to avoid this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants