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

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

Open
ockham opened this issue Jul 3, 2024 · 1 comment
Open

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

ockham opened this issue Jul 3, 2024 · 1 comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended

Comments

@ockham
Copy link
Contributor

ockham commented Jul 3, 2024

Description

While working on #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 #43917 and amended by #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 ockham added [Type] Bug An existing feature does not function as intended [Tool] WP Scripts /packages/scripts labels Jul 3, 2024
@ockham
Copy link
Contributor Author

ockham commented Jul 3, 2024

The same problem will also apply to the variations field, if we extend it to allow filenames (i.e. variations.php), see #62092.

ockham added a commit that referenced this issue Jul 17, 2024
If a `block.json`'s `variations` field is set to a (PHP) file name, include that file in the build, i.e. prefix its functions with `gutenberg_` and copy the resulting file to the `build/block-library/blocks/` directory.

Note that this applies to third-party blocks, but not Core blocks. Making it work for Core blocks is a separate issue: #63077.

Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this issue Jul 18, 2024
If a `block.json`'s `variations` field is set to a (PHP) file name, include that file in the build, i.e. prefix its functions with `gutenberg_` and copy the resulting file to the `build/block-library/blocks/` directory.

Note that this applies to third-party blocks, but not Core blocks. Making it work for Core blocks is a separate issue: WordPress#63077.

Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
@gziolo gziolo added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Build Tooling Issues or PRs related to build tooling and removed [Tool] WP Scripts /packages/scripts [Type] Build Tooling Issues or PRs related to build tooling labels Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants