Slate: Deleting selection across nested blocks results in an error (`Node.assertNode` could not find node with path or key)

Created on 26 Oct 2018  ·  5Comments  ·  Source: ianstormtaylor/slate

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

Bug. 🐛

What's the current behavior?

When you select a list branch with more then three levels of nesting and try to delete it, it will result in an error. For example:

Node.assertNode could not find node with path or key: List [ 0, 1, 0, 0, 0, 0 ]

This behavior, however, won't happen when you select multiple branches (see the recording).

CodeSandbox reproduction

https://codesandbox.io/s/6ykzw473wz

GIF

GIF

Environment

What's the expected behavior?

Expected behavior is to delete the selected content.

bug ♥ help

Most helpful comment

I'm pretty sure it's happening here packages/slate/src/utils/path-utils.js#L323

The operation:

{
  "object": "operation",
  "type": "merge_node",
  "path": [
    0,
    1,
    0,
    1
  ],
  "position": 0,
  "properties": {
    "data": {}
  },
  "target": null
}

The result is List [ 0, 1, 0, 0, 0, 0 ]

pIndex is 3

The correct result should be List [ 0, 1, 0, 0]

Commenting out the else if makes my test pass (but of course breaks others tests), so it seems like there is missing an additional conditional there, but I have no idea what. Tried various.

  if (type === 'merge_node') {
    if (pEqual || pYounger) {
      path = decrement(path, 1, pIndex)
    } else if (pAbove) {
      // path = decrement(path, 1, pIndex)
      // path = increment(path, position, pIndex + 1)
    }
  }

@ianstormtaylor any ideas?

The replicated test document:

  <value>
    <document>
      <list>
        <item>
          <paragraph>
            If you start selecting here the issue won't occur.
          </paragraph>
        </item>
        <item>
          <paragraph>
            <anchor />START selecting here.
          </paragraph>
          <list>
            <item>
              <paragraph>Selected</paragraph>
            </item>
            <item>
              <paragraph>Selected</paragraph>
            </item>
            <item>
              <paragraph>Selected</paragraph>
              <list>
                <item>
                  <paragraph>Selected</paragraph>
                </item>
                <item>
                  <paragraph>
                    END selection here<focus />
                  </paragraph>
                </item>
              </list>
            </item>
          </list>
        </item>
      </list>
    </document>
  </value>

All 5 comments

I'm pretty sure it's happening here packages/slate/src/utils/path-utils.js#L323

The operation:

{
  "object": "operation",
  "type": "merge_node",
  "path": [
    0,
    1,
    0,
    1
  ],
  "position": 0,
  "properties": {
    "data": {}
  },
  "target": null
}

The result is List [ 0, 1, 0, 0, 0, 0 ]

pIndex is 3

The correct result should be List [ 0, 1, 0, 0]

Commenting out the else if makes my test pass (but of course breaks others tests), so it seems like there is missing an additional conditional there, but I have no idea what. Tried various.

  if (type === 'merge_node') {
    if (pEqual || pYounger) {
      path = decrement(path, 1, pIndex)
    } else if (pAbove) {
      // path = decrement(path, 1, pIndex)
      // path = increment(path, position, pIndex + 1)
    }
  }

@ianstormtaylor any ideas?

The replicated test document:

  <value>
    <document>
      <list>
        <item>
          <paragraph>
            If you start selecting here the issue won't occur.
          </paragraph>
        </item>
        <item>
          <paragraph>
            <anchor />START selecting here.
          </paragraph>
          <list>
            <item>
              <paragraph>Selected</paragraph>
            </item>
            <item>
              <paragraph>Selected</paragraph>
            </item>
            <item>
              <paragraph>Selected</paragraph>
              <list>
                <item>
                  <paragraph>Selected</paragraph>
                </item>
                <item>
                  <paragraph>
                    END selection here<focus />
                  </paragraph>
                </item>
              </list>
            </item>
          </list>
        </item>
      </list>
    </document>
  </value>

same error in Microsoft Edge 12 when I dragging text.

@skogsmaskin what is the initial path (passed into transform), the operation (passed into transform) and the resulting path (the return value of transform) in that case?

a failing test with this would be nice :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vdms picture vdms  ·  3Comments

chrpeter picture chrpeter  ·  3Comments

JSH3R0 picture JSH3R0  ·  3Comments

chriserickson picture chriserickson  ·  3Comments

AlexeiAndreev picture AlexeiAndreev  ·  3Comments