justintadlock / block-pattern-builder

Build block patterns from the WordPress admin.
GNU General Public License v2.0
41 stars 9 forks source link

Editor crashes if you unregister the core block patterns (due to missing categories) #21

Open skorasaurus opened 3 years ago

skorasaurus commented 3 years ago

Hi,

When a user unregisters the core-block-patterns that ship with gutenberg/block editor, (this can be done by remove_theme_support( 'core-block-patterns' ); within an init or after_theme_setup hook) (ref: https://fullsiteediting.com/lessons/block-patterns-tips/), the block editor will crash if you have any block patterns made with the block-pattern-builder.

I've reproduced this in Gutenberg 9.4.1 and in a copy that I built a few minutes ago from the master branch of the gutenberg repo.

I'm pretty sure this is a result of a lack of categories support in the block-pattern-builder; I'm not able to reproduce this when I delete the bpb_pattern from my posts list.

To reproduce:

  1. create a pattern with the block pattern builder and publish
  2. unregister the core block patterns in the active theme
    add_action( 'after_setup_theme', 'test_case_setup' );
    function test_case_setup() {
    remove_theme_support( 'core-block-patterns' );
    }
  3. create a new post, select the pattern in the toolbar.

Editor crashes

console:

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

villekautto commented 3 years ago

I can confirm the editor crashing if core patterns are unregistered. The pull request https://github.com/justintadlock/block-pattern-builder/pull/17 appears to fix this issue (tested just now) but it's not yet merged and it has some minor issues still.

ghost commented 3 years ago

Very interested in getting this fix in place.