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.

Nested blocks issue

See original GitHub issue

There is problem with transformations of doubly nested blocks (document - documentNode - nestedNode - doubleNestedNode). There is problem in following cases:

  • caret at end of the doubleNestedNode, press delete
  • caret at beggining of (not first) node, press backspace
  • paste selection of more than one block
Uncaught Error: Could not find a node with key "47".
    at Document.assertNode
    at Object.normalizeNodeByKey
    at Transform.(anonymous function) [as normalizeNodeByKey] 
    at Object.deleteAtRange
    at Transform.(anonymous function) [as deleteAtRange]
    at Object.deleteBackwardAtRange
    at Transform.(anonymous function) [as deleteBackwardAtRange] 
    at Object.deleteCharBackwardAtRange
    at Transform.(anonymous function) [as deleteCharBackwardAtRange] 
    at Object.deleteCharBackward

Double nested blocks have actually multiple issues and strange behaviors that regular nested blocks does not have. For example backspace with caret at first double nested block deletes without producing error, but deletes whole content of nestedBlock keeping only first doubleNestedBlock.

I am aware that this could be solved with custom plugin, but since Slate supports unlimited nesting of blocks, this should be probably solved in core.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
erquhartcommented, Jul 11, 2017

@Mangatt agreed, there appears to be a class of issues related to deeply nested block handling.

I opened #917 to address one aspect of it. Here’s what I found (again, just one aspect of a greater issue):

  • Insert a fragment containing two sibling leaf blocks nested more than one layer deep.
  • Example: A list with a single list item, and that list item contains two paragraphs with text.
  • Transform.insertFragmentAtRange checks the first and last leaf blocks, and if they are not the same, it removes the parent of the first leaf block pending a potential node split. The intention is to add the first leaf node parent back in after the split.
  • In this case, the first and last leaf node share the same parent, so both nodes are inadvertently removed. I believe this is due to this line, where the iterator for finding lonelyParent simply requires the parent to contain only one node. This doesn’t account for that one node having multiple children.
  • We then attempt to move the last leaf node into the document, but it’s been removed from the fragment, hence the error associated with moveNodeByKey.

I’ve minimally reproduced this in a Fiddle: https://jsfiddle.net/erquhart/L05uz8qp/2/

My PR addresses this particular case, but there seem to be many more. For example, if you paste into a selection, which requires a split, you get new errors associated with marks.

The ideal approach is to find the underlying shared assumptions that cause deeply nested fragments to be mishandled.

@ianstormtaylor we’ll likely need your help getting this going. Do you recall running into any issues like this?

1reaction
ianstormtaylorcommented, Aug 8, 2018

This issue hasn’t had a response in a while, and it’s unclear if it’s still present in the latest versions of Slate. To keep the issues easier to manage, since there are so many being opened every day, I’m going to close this old one out.

But if you notice that the bug is still happening, please feel free to comment and it can be revisited. It might be an edge case that not many people run into, in which case the fastest way to get it fixed would probably be to write a pull request for it.

Thanks for understanding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Problem with Nested Blocks and AdditionalViewData - Blog
This issue can happen with any data passed with PropertyFor as additionalViewData. It can be as minor as a persisting CssClass, or more...
Read more >
Nested blocks are triggering error · Issue #109 - GitHub
When nesting blocks error is triggered. Block of code is taken from latte documentation (https://latte.nette.org/en/tags#toc-blocks) so it should be OK.
Read more >
Nested block issues - Rhino for Windows - McNeel Forum
I am working on a project with big components that I split up into blocks. Say Block_A and Block_B. I then have a...
Read more >
What problems are caused by nested Blocks? - Stack Overflow
First of all a block copies "virtually" all reachable local vars of a program. Of course this is optimized by the compiler.
Read more >
Nested Blocks: Using InnerBlocks | Block Editor Handbook
A common pattern for using InnerBlocks is to create a custom block that will be included only in the InnerBlocks. An example of...
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