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

@wordpress/scripts doesn't detect render PHP files without a restart #49790

Closed
aurooba opened this issue Apr 13, 2023 · 5 comments
Closed

@wordpress/scripts doesn't detect render PHP files without a restart #49790

aurooba opened this issue Apr 13, 2023 · 5 comments
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling

Comments

@aurooba
Copy link
Member

aurooba commented Apr 13, 2023

Description

If you have @wordpress/scripts running with the start script, and add a "render": "file:./render.php" to your block.json file, the script doesn't detect it. But if you end the process and restart it, then it does.

It's very possible I'm just missing something, but I can't figure out why this is happening! I don't recall it being an issue before.

Step-by-step reproduction instructions

  1. Create a new block plugin with npx @wordpress/create-block todo-list
  2. Run npm run start
  3. Add a render.php file in the src folder
  4. Add "render": "file:./render.php" to your block.json file.
  5. See that the render.php never makes it to the build folder
  6. Kill the script in your terminal
  7. Run npm run start again.
  8. See that the render.php now appears in your build folder

Screenshots, screen recording, code snippet

block.json

{
	"$schema": "https://schemas.wp.org/trunk/block.json",
	"apiVersion": 2,
	"name": "create-block/todo-list",
	"version": "0.1.0",
	"title": "Todo List",
	"category": "widgets",
	"icon": "smiley",
	"description": "Example block scaffolded with Create Block tool.",
	"supports": {
		"html": false
	},
	"textdomain": "todo-list",
	"editorScript": "file:./index.js",
	"editorStyle": "file:./index.css",
	"style": "file:./style-index.css",
	"render": "file:./render.php"
}

render.php

<?php
echo 'Hello World!';

Screenshot of the src folder

shows the src folder with a block.json file, edit.js file, editor.scss file, index.js file, render.php file, save.js file, and style.scss file

Environment info

  • WordPress 6.2

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

@Thelmachido Thelmachido added [Type] Bug An existing feature does not function as intended Needs Testing Needs further testing to be confirmed. labels Apr 13, 2023
@kathrynwp kathrynwp added the [Type] Build Tooling Issues or PRs related to build tooling label Apr 13, 2023
@gziolo
Copy link
Member

gziolo commented Apr 17, 2023

Thank you for opening this issue, @aurooba. I haven’t tested it yet but I’m quite sure that the issue exists based on the following findings in the code.

There is a single place in the webpack config that collects all paths for all render occurrences in existing block.json files:

const renderPaths = getRenderPropPaths();

It never gets recalculated in the watch mode, so it doesn't have a chance to detect a new file when processing inside the copy plugin:

https://github.com/WordPress/gutenberg/blob/c475dcb3ffee7627a8e1d2f13f364a7a9b195a61/packages/scripts/config/webpack.config.js#L273L283

@gziolo gziolo added Good First Issue An issue that's suitable for someone looking to contribute for the first time [Tool] WP Scripts /packages/scripts and removed Needs Testing Needs further testing to be confirmed. labels Apr 17, 2023
@aurooba
Copy link
Member Author

aurooba commented Apr 17, 2023

@gziolo That makes sense. I can take a look at this later this week and help fix it. I've been diving into the wp-scripts code to understand it better overall, so I've started to get a good handle on it.

@gziolo
Copy link
Member

gziolo commented Apr 18, 2023

I can take a look at this later this week and help fix it. I've been diving into the wp-scripts code to understand it better overall, so I've started to get a good handle on it.

Fantastic! 😀

@gziolo
Copy link
Member

gziolo commented Jun 1, 2023

Fixed with #50939.

@gziolo
Copy link
Member

gziolo commented Jun 1, 2023

I opened a follow-up #51162 with some performance optimization to the webpack configuration for detecting render PHP files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

No branches or pull requests

4 participants