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

Editor crashes with error “TypeError: Cannot read property 'apiVersion' of undefined” #32815

Closed
markhowellsmead opened this issue Jun 18, 2021 · 15 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended

Comments

@markhowellsmead
Copy link

Description

If a block is in the post content which is no longer registered, the editor crashes irretrievably with the error message TypeError: Cannot read property 'apiVersion' of undefined.

Step-by-step reproduction instructions

  1. Open the editor of a post containing a block which is no longer registered.
  2. Click into the editor.

Expected behaviour

I should be able to manually delete the block which is no longer registered.

Actual behaviour

The editor throws the “unexpected error” message and cannot be recovered using any of the available options.

WordPress information

  • WordPress version: 5.7.2
  • Gutenberg version: Not installed
  • Are all plugins except Gutenberg deactivated? Yes
  • Are you using a default theme (e.g. Twenty Twenty-One)? No

Device information

  • Device: Desktop
  • Operating system: OSX
  • Browser: Brave 1.25.73, Chrome 91. Firefox shows a classic editor element instead of the usual "block not supported" message in the editor, which can successfully be removed.
@Mamaduka Mamaduka added [Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended labels Jun 18, 2021
@gziolo gziolo self-assigned this Aug 27, 2021
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Aug 27, 2021
@gziolo
Copy link
Member

gziolo commented Aug 27, 2021

I tested it with the latest Gutenberg plugin activated and with WordPress 5.8.0. I couldn't reproduce the issue. I see in the code a few places that @glendaviesnz added in #25940 additional checks whether blockType object is defined when accessing apiVersion. I searched through the code and noticed a few more places so I plan to open PR with some code quality improvements that might prevent some edge cases.

@gziolo
Copy link
Member

gziolo commented Aug 27, 2021

I opened #34346 with a changes that check if the blockType is defined before accessing apiVersion in 3 more places.

The remaining question is whether we want to do anything about WordPress 5.7. We didn't see similar reports before so it's hard to tell if that isn't related to the theme used. It needs to be tested with WordPress 5.7 and the default theme to verify how serious this issue is.

@gziolo gziolo added Needs Testing Needs further testing to be confirmed. and removed [Status] In Progress Tracking issues with work in progress labels Aug 27, 2021
@gziolo gziolo removed their assignment Aug 27, 2021
@markhowellsmead
Copy link
Author

markhowellsmead commented Nov 10, 2021

Current status with WordPress 5.8.1 and Plugin version 11.8.3. The editor no longer crashes. The block which was formerly registered and filled with content is visible, but clicking on it removes everything except a simple, unlabelled control, which allows the user to remove the block. This is a good solution, but the interface needs to show some kind of label to indicate to the user what is happening/what has happened.

Screenshot 2021-11-10 at 12 30 29

@gziolo
Copy link
Member

gziolo commented Nov 10, 2021

@noisysocks and @Mamaduka, I wanted to flag this issue for your consideration in the context of the upcoming 5.9 release. The last update shared in #32815 (comment) is the only remaining concern.

@markhowellsmead
Copy link
Author

Additional: this appears to only apply to core blocks. De-registering a custom block where content has already been created shows a suitable message and action control.

Screenshot 2021-11-10 at 12 46 48

@StefanXhunga
Copy link

I think is Ok, thank you for your assistance!

@Mamaduka
Copy link
Member

Thanks for the ping, @gziolo.

We should display a similar message for core blocks as we do for custom ones - #32815 (comment). What do you think?

@glendaviesnz glendaviesnz self-assigned this Dec 14, 2021
@glendaviesnz
Copy link
Contributor

On GB trunk on WP 5.8 if I deregister the core/image block and then load an image block into the editor it shows the standard unrecognised block error message:

no-core

@markhowellsmead, how did you deregister the block in order to get the empty block toolbar

@markhowellsmead
Copy link
Author

markhowellsmead commented Dec 15, 2021

Please refer to #32815 (comment) in which I confirm that this relates to custom blocks, not core blocks.

unregisterBlockType('core/image')

@markhowellsmead
Copy link
Author

Note that you have to add the block, save the post, then amend the code to deregister the block which is already placed in the content, then reload the editor.

@glendaviesnz
Copy link
Contributor

Note that you have to add the block, save the post, then amend the code to deregister the block which is already placed in the content, then reload the editor.

I get the same result doing this as when unregistering in the terminal and pasting the block markup into the editor terminal view. Below I add a quote block, then in a plugin add unregisterBlockType( 'core/quote' ) and reload the editor, and the same message appears as for non-core blocks:

no-quote

Are you still seeing this error on latest trunk @markhowellsmead?

@Mamaduka
Copy link
Member

Mamaduka commented Jan 5, 2022

Hi, folks

I'm removing this issue from WP 5.9 project board since RC1 was released last night.

Let's try and land a fix for this in a minor release.

@glendaviesnz glendaviesnz removed their assignment Feb 11, 2022
@ndiego
Copy link
Member

ndiego commented Aug 2, 2022

I just tested with a few custom blocks and there is now a clear message that the block is disabled. See screenshot below with the Icon Block. I believe this issue can be closed.

image

@Mamaduka
Copy link
Member

Mamaduka commented Aug 2, 2022

Thanks, @ndiego.

@markhowellsmead, I'm going to close the issue.

We shipped several improvements for missing blocks, but feel free to re-open if you encounter new errors.

@Mamaduka Mamaduka closed this as completed Aug 2, 2022
@Mamaduka Mamaduka removed the Needs Testing Needs further testing to be confirmed. label Aug 2, 2022
@markhowellsmead
Copy link
Author

Thanks for the feedback. Seems to work and provides the natural error message when a newly-unregistered block is in the block editor.

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. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

6 participants