Skip to content

Block Patterns without a category crashes the block editor #27249

Description

@skorasaurus

Describe the bug

Accessing a registered block pattern that has doesn't have a categories objects crashes the block editor.

According to the existing documentation , a category is not required.

To reproduce
You must first activate a theme that does not have any of its own block patterns shipped with it. (e.g. blankslate is one example)

  1. Register a block pattern without a category; example below, can be placed in your theme's functions.php or wherever you prefer.
register_block_pattern(
	'skorasaurus/test-case-block-pattern',
	array(
		'title'       => __( 'a simple heading', 'what should this be' ),
		'description' => _x( 'mmm..cake', ' this is slang and has more nuance in english', ''),
		'content'     => '<!-- wp:heading -->
		<h2>The history of cake</h2>
		<!-- /wp:heading -->',
	)
);
  1. add the remove_theme_support('core-block-patterns');
  2. create a new post or page in block-editor
  3. Go to the patterns tab
  4. "The editor has encountered an unexpected error." appears; and in console, the following:
Uncaught TypeError: t.categories is undefined
    s https://local.wordpress.test/wp-content/plugins/gutenberg/build/block-editor/index.js?ver=fdb8c27842d6665c8f717ab07efd9458:30
    s https://local.wordpress.test/wp-content/plugins/gutenberg/build/block-editor/index.js?ver=fdb8c27842d6665c8f717ab07efd9458:30
    s https://local.wordpress.test/wp-content/plugins/gutenberg/build/block-editor/index.js?ver=fdb8c27842d6665c8f717ab07efd9458:30
    mountMemo https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:15577
    useMemo https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:15873
    useMemo https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react.af754d50.js:1607
    is https://local.wordpress.test/wp-content/plugins/gutenberg/build/block-editor/index.js?ver=fdb8c27842d6665c8f717ab07efd9458:30
    renderWithHooks https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:14938
    mountIndeterminateComponent https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:17617
    beginWork https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:18731
    callCallback https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:182
    invokeGuardedCallbackDev https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:231
    invokeGuardedCallback https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:286
    beginWork$1 https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:23338
    performUnitOfWork https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:22289
    workLoopSync https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:22265
    performSyncWorkOnRoot https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:21891
    flushSyncCallbackQueueImpl https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:11224
    unstable_runWithPriority https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react.af754d50.js:2685
    runWithPriority$1 https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:11174
    flushSyncCallbackQueueImpl https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:11219
    flushSyncCallbackQueue https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:11207
    discreteUpdates$1 https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:22028
    discreteUpdates https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:803
    dispatchDiscreteEvent https://local.wordpress.test/wp-content/plugins/gutenberg/vendor/react-dom.82e849f1.js:4291

Expected behavior
The block pattern to load.

Screenshots
If applicable, add screenshots to help explain your problem.

Editor version (please complete the following information):

  • WordPress version: 5.5
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? [e.g: "gutenberg plugin",
  • If the Gutenberg plugin is installed, which version is it? 9.4.1

Still reproducible in WordPress 5.8 and Gutenberg 11.2.1

I was able to reproduce this in Gutenberg 9.1.0; I was not able to reproduce this in Gutenberg 9.0.0

Metadata

Metadata

Labels

[Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions