WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.16k stars 4.05k forks source link

block.json: `render` files not copied to `build/` folder for Core blocks #63077

Open ockham opened 2 weeks ago

ockham commented 2 weeks ago

Description

While working on https://github.com/WordPress/gutenberg/pull/62092, I discovered that if a Core block's block.json file contains a render field that specifies a PHP file to render the block, that file is not copied to the build/ folder. This means that if a Core block were to use the render field, it would break.

The same is not a problem for third-party blocks, as they are handled by code in wp-scripts (added by https://github.com/WordPress/gutenberg/pull/43917 and amended by https://github.com/WordPress/gutenberg/pull/51162).

By contrast, Core blocks are built using a special Webpack config in; while there is code to copy their index.php files to the build/ folder, there's none to handle render files.

This is currently reflected by the fact that no Core blocks are using the render field. However, it is somewhat confusing that they cannot use a documented API that is available for third-party blocks.

Step-by-step reproduction instructions

The following patch moves the Template Part block's render callback from its index.php to a newly created render.php, and adds a render field to block.json that points to that file.

Apply the patch and rebuild Gutenberg. Note that Template Part blocks no longer work on the frontend (they appear blank), and that the render.php file is missing from build/block-library/blocks/template-part/.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

ockham commented 2 weeks ago

The same problem will also apply to the variations field, if we extend it to allow filenames (i.e. variations.php), see https://github.com/WordPress/gutenberg/pull/62092.