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

A missing/unregistered block in a template crashes the post editor #21718

Closed
chrisvanpatten opened this issue Apr 19, 2020 · 7 comments
Closed
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended

Comments

@chrisvanpatten
Copy link
Contributor

Describe the bug

If a post type block template references a block which is not registered, the editor crashes with a whitescreen.

To reproduce

Steps to reproduce the behavior:

  1. Create a post type template with a block that does not exist:
register_post_type(
    // attributes
    'template' => [
        [ 'fake/block', [] ],
    ]
);
  1. Create a new post for that post type
  2. Observe white screen
  3. See error: Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'n.attributes') (full trace below)

Expected behavior

While this is clearly an error, it would be nice if it were handled better. At the very least, a more descriptive console message would be great. Even better would be to show an error in the standard error boundary template so the rest of the core UI is available.

Screenshots

Screen Shot 2020-04-19 at 5 20 30 PM

Editor version (please complete the following information):

  • WordPress version: 5.3 branch
  • Gutenberg plugin: 7.9.1

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Safari + Chrome tested

Additional context

Stack trace, in the event that it's helpful:

[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'n.attributes')
	dispatchException (wp-polyfill.min.js:1:97215)
	invoke (wp-polyfill.min.js:1:92747)
	(anonymous function) (index.js:1:5094)
	c (index.js:1:5232)
	t (index.js:1:5488)
	initializePromise
	Promise
	(anonymous function) (index.js:1:9537)
	(anonymous function) (index.js:11:177013)
	(anonymous function) (index.js:1:16699)
	r (index.js:11:166130)
	Ag (react-dom.min.js:63:113)
	Vg (react-dom.min.js:89:445)
	lh (react-dom.min.js:126:412)
	O (react-dom.min.js:121)
	O
	ze (react-dom.min.js:118)
	ze
	(anonymous function) (react-dom.min.js:53)
	unstable_runWithPriority (react.min.js:26:342)
	mg (react-dom.min.js:52:499)
	V (react-dom.min.js:52:434)
	Sb (react-dom.min.js:213:98)
	Mg (react-dom.min.js:85:83)
	Mg
	e (index.js:1:27494)
	(anonymous function) (index.js:1:27578)
	forEach
	o (index.js:1:21480)
	(anonymous function) (index.js:1:18707)
	p (index.js:1:11333)
	n (index.js:1:9451)
	some
	e (index.js:1:5181)
	(anonymous function) (index.js:1:5131)
	promiseReactionJob
@ntsekouras
Copy link
Contributor

Hey thanks for reporting this! - This has been fixed with a specific error message here: #24287

@ntsekouras
Copy link
Contributor

ntsekouras commented Oct 15, 2020

I'll reopen this issue as this should be handled better other than having a better message. There is some context for handling this here: #26147 (comment), #26147 (comment)

@ntsekouras ntsekouras reopened this Oct 15, 2020
@talldan talldan added the [Type] Bug An existing feature does not function as intended label Dec 16, 2020
@ntsekouras ntsekouras changed the title Improve error handling for post type templates with non-existent blocks A missing/unregistered block in a template crashes the post editor Dec 16, 2020
@peterhebert
Copy link

Have run into this also, with a block template using a block provided by a plugin, when the plugin got disabled:
Uncaught (in promise) Error: Block type 'coblocks/social-profiles' is not registered.

Causes blank white screen. This really should fail more gracefully, and either just ignore the missing block or have message where block is placed in template that it does not exist. Should not block editor from loading.

@CreativeDive
Copy link
Contributor

This same thing happened if I try to add a new "block template" in the block editor sidebar. In my case if have disabled the core block "core/separator" in the following way:

wp.blocks.unregisterBlockType( 'core/separator' );

But if the default template includes a "core/separator" block as a part of the template, this breaks all. The template editor dosen't work in this case. I get a white screen.

Removing wp.blocks.unregisterBlockType( 'core/separator' ); solves that. But this is a bug in my eyes. The editor should not break if a not registered block was called.

@mauteri
Copy link
Contributor

mauteri commented Dec 29, 2021

Hi! I create a PR in an attempt to improve the user experience with this issue. I see recent changes have removed the white screen, which is great. In my change I'm looking to mimic the experience of a post edit that is missing a block, and utilize the core/missing block in the createBlock function if a block isn't registered. This keeps the layout intact where blocks are registered, and calls out the block that is not registered within the editor with core/missing block.

This is my first contribution to the project, so I'm also looking to learn and open to making any adjustments to improve this code. Thanks! :-)

#37646

@mauteri
Copy link
Contributor

mauteri commented Jan 6, 2022

My PR above has been merged to trunk, so this ticket can probably be closed now.

New user experience retains any registered blocks in a template and uses core/missing block for any unregistered blocks in a template. More notes about specifics handlings are provided in the comments of the PR. Thanks!

@amustaque97
Copy link
Member

My PR above has been merged to trunk, so this ticket can probably be closed now.

PR link: #37646

Closing this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants