Gutenberg: Removing last inner block using keyboard shortcut crashes editor

Created on 19 Jul 2019  路  6Comments  路  Source: WordPress/gutenberg

Describe the bug

This is basically the same issue as #15543 / #15786, however this time it happens when using the keyboard shortcut for block deletion and not when using the UI.

To reproduce
Steps to reproduce the behavior:

  1. Add new Group block
  2. Add new Paragraph block within that Group block
  3. Make sure the Paragraph block is selected
  4. Use keyboard shortcut to delete block (control+option+z on macOS)
  5. Editor crashes.

Error message:

TypeError: Cannot read property 'name' of null
    at isPossibleTransformForSource (https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7775:84)
    at https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7845:14
    at _loop (https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7966:9)
    at findTransform (https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7974:5)
    at https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7844:14
    at arrayFilter (https://wordpress.local/wp-content/plugins/gutenberg/vendor/lodash.e6dd46ff.js:582:11)
    at filter (https://wordpress.local/wp-content/plugins/gutenberg/vendor/lodash.e6dd46ff.js:9173:14)
    at getBlockTypesForPossibleFromTransforms (https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7842:99)
    at getPossibleBlockTransformations (https://wordpress.local/wp-content/plugins/gutenberg/build/blocks/index.js?ver=1563205142:7941:37)
    at BlockSwitcher.render (https://wordpress.local/wp-content/plugins/gutenberg/build/block-editor/index.js?ver=1563205142:16490:241)

Expected behavior
Block is removed without the editor crashing.

Screenshots
Screenshot 2019-07-19 at 11 31 47

Additional context

  • Gutenberg version 6.1.1 / current master
[Feature] Blocks [Feature] Nested / Inner Blocks [Type] Bug [a11y] Keyboard & Focus

Most helpful comment

I could reproduce this in the last plugin release, but not in master. That being said, even if it's now fixed, I'd not want to consider it as closed until understanding what the issue was.

I've seen it before that getBlocksByClientId can return [ null ]. This shouldn't be expected. I'm having trouble finding where it was that I encountered this before. There's possibly some race conditions (possibly in nested blocks or with the async rendering of blocks) that cause a desync between the block data and the block order (block-editor's blocks.byClientId and blocks.order state). There are some higher-order reducers there operating with cascading effects in nested blocks (and especially removals) that are suspect. I think @youknowriad mentioned some potential "orphan" issues he had encountered recently in some unrelated work (maybe his changes were the fix?).

I ran out of time while I was debugging it, but would like to revisit it tomorrow.

All 6 comments

cc @aduth because you were very helpful and patient the last time this happened :-) Maybe you have an idea here?

I wasn't able to reproduce:
group-delete-paragraph

After deleting using the keyboard shortcut the button inserter displays again. Are there any steps when reproducing that I might be missing, @swissspidy?

Weird. It's actually pretty straightforward. I also recorded a quick video now: https://cloudup.com/cnMYyRdh2X3

More additional context:

  • Current Gutenberg master (b0884b75217cf10ea8e2707b9f3eac56bff8a5f5 as of this writing)
  • WordPress 5.2.2
  • Twenty Seventeen
  • No other plugins installed
  • US keyboard

Going through the stack trace it seems like wp.data.select( 'core/block-editor' ).getBlocksByClientId() returns [ null ] after the block removal, causing things like getPossibleBlockTransformations( blocks ) in BlockSwitcher to fail.

I could reproduce this in the last plugin release, but not in master. That being said, even if it's now fixed, I'd not want to consider it as closed until understanding what the issue was.

I've seen it before that getBlocksByClientId can return [ null ]. This shouldn't be expected. I'm having trouble finding where it was that I encountered this before. There's possibly some race conditions (possibly in nested blocks or with the async rendering of blocks) that cause a desync between the block data and the block order (block-editor's blocks.byClientId and blocks.order state). There are some higher-order reducers there operating with cascading effects in nested blocks (and especially removals) that are suspect. I think @youknowriad mentioned some potential "orphan" issues he had encountered recently in some unrelated work (maybe his changes were the fix?).

I ran out of time while I was debugging it, but would like to revisit it tomorrow.

My changes to fix the "orphan" issues has landed in the previous release, so might be something different. This could be something similar to undo/redo issues where we reference block IDs that were removed in reducers other than the blocks reducer.

Can't reproduce this anymore.

Was this page helpful?
0 / 5 - 0 ratings