Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

WP 5.0.1 with built-in Gutenberg gives TypeError: "middleware.fields is undefined" #85

Closed
colorcube opened this issue Dec 17, 2018 · 2 comments

Comments

@colorcube
Copy link

JS error:

TypeError: "middleware.fields is undefined"

Blocks which uses middleware are not working when the built-in Gutenberg is used with WP 5.0.1.

Maybe because the middleware js is loaded after the editor js. Just a guess.

When installing the gutenberg plugin everything works as expected.

@mohdsayed
Copy link
Member

mohdsayed commented Dec 23, 2018

Thanks for trying @colorcube , I just tested with WordPress 5.0.2 however wasn't able to replicate the error. Would you be able to give me steps to produce this error?
You may also take a look at https://github.com/rtCamp/gutenberg-supplements which is created with Gutenberg Fields Middleware for reference.

@colorcube
Copy link
Author

I found the problem.
I used wp_cli scaffolding for my custom gutenberg block, like:

wp-cli.phar scaffold block my-custom

In the generated code there's a function to register the block JavaScript with wp_register_script(). So far so good.

But the function will be called with this hook:

add_action('init', 'my_custom_block_init');

gutenberg-fields-middleware uses the hook 'enqueue_block_editor_assets' which seems to be called later.

I changed my hook registration to

add_action('enqueue_block_editor_assets', 'my_custom_block_init');

and everything works fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants