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

Deleting first item in an InnerBlocks list with delete key causes exception #29498

Closed
glendaviesnz opened this issue Mar 3, 2021 · 12 comments · Fixed by #32088
Closed

Deleting first item in an InnerBlocks list with delete key causes exception #29498

glendaviesnz opened this issue Mar 3, 2021 · 12 comments · Fixed by #32088
Assignees
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@glendaviesnz
Copy link
Contributor

Description

If the delete key or keyboard shortcut is used to delete the first item in an InnerBlocks list an exception is thrown. Using the 'Remove block' menu option for the block works as expected. Using the delete key for any block other than the first one also works as expected.

This issue can be replicated with the Navigation block, and also on the gallery block refactor PR

Step-by-step reproduction instructions:

  1. Add a Navigation block and add several child navigation items to it.
  2. Select the first item in the navigation and hit delete key to remove
  3. Block shows unable to preview message and exception in console

deletekey

Code snippet

Exception is thrown at https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/block-list/use-block-props/index.js#L86

For some reason the useBlockProps hook for the block that has been deleted gets stuck in a loop and throws an exception when trying to get the title of the block that is now deleted.

@glendaviesnz glendaviesnz added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Mar 3, 2021
@Quintis1212
Copy link
Contributor

Hello ) I can reproduce this bug ) I will try to fix it )

@Quintis1212
Copy link
Contributor

Quintis1212 commented Mar 3, 2021

In my closed PR I fix yours bug , you just need to add more dependence to select function :
0e0eae3

In the latest version gutenberg there is no such bug

@talldan
Copy link
Contributor

talldan commented Mar 9, 2021

@glendaviesnz I was checking if this was affected by #29059, but I can't reproduce this one in trunk, would you be able to see if it's still happening?

@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Mar 9, 2021

@glendaviesnz I was checking if this was affected by #29059, but I can't reproduce this one in trunk, would you be able to see if it's still happening?

It doesn't happen in trunk for me with the navigation block, but I just rebased the Gallery PR and it still happens with that block - strange that it fixed it for one and not the other, but gallery has a slightly different innerBlock structure to the navigation block.

@talldan
Copy link
Contributor

talldan commented Mar 11, 2021

Also reported on #29722, this also happens when deleting a Page List block from within the Navigation block.

Closing that one as a duplicate.

@talldan
Copy link
Contributor

talldan commented Mar 11, 2021

The main cause seems to be that useBlockProps assumes that a block will always be defined, but when deleting, momentarily it isn't defined.

There seem to be a few cases where that's causing an issue:

I think it's a similar issue to what Riad describes on this PR - #29059.

@talldan talldan added the [Priority] High Used to indicate top priority items that need quick attention label Mar 18, 2021
@talldan
Copy link
Contributor

talldan commented Mar 18, 2021

Also reported in #29958.

@paaljoachim
Copy link
Contributor

paaljoachim commented Apr 3, 2021

Using the Backspace/Del key might cause a block error.

I was just about to create an issue for what I believe is the same error. As I was in the Site Editor in TT1.
I have earlier mentioned the error for Glen in relation to the updated Gallery block.

I am using WordPress 5.7.
Theme: TT1
Gutenberg plugin 10.3.1

Do-not-click-the-back-arrow-button-or-else-the-block-will-explode.mp4

@leeshadle
Copy link

I'm not sure if this is related, but I'm getting an error after updating to Gutenberg versions 10.3 & 10.3.1:
"Uncaught TypeError: Cannot read property 'apiVersion' of undefined"

I built a package that allows me to hot reload blocks during development.

During development, if a registered block's code changes I run unregisterBlockType(). I then immediately run registerBlockType() with the updated block's code.

I'm not sure what's causing the error, but it appears that the BlockListBlock component re-renders despite the block being unregistered?

Screen Shot 2021-04-05 at 1 20 21 PM

@markhowellsmead
Copy link

The error Cannot read property 'apiVersion' of undefined is also thrown when trying to delete a block in the editor which is no longer registered.

@klokie
Copy link

klokie commented Apr 10, 2021

I'm seeing what seems to be the same issue presented when following the recommended practice for replacing editor content, i.e. using resetBlocks().

@annezazu
Copy link
Contributor

annezazu commented May 6, 2021

Noting that I found this error when deleting the Featured Image Block inside a Query Block. This was found as part of the fifth call for testing for the FSE Outreach Program:

bug.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants