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

fix: build render.php when webpack watch in progress #50939

Merged
merged 2 commits into from
Jun 1, 2023

Conversation

Takshil-Kunadia
Copy link
Contributor

@Takshil-Kunadia Takshil-Kunadia commented May 25, 2023

PR For :- Issue #49790

What?

Why?

  • Based on these findings by @gziolo
  • Webpack's CopyWebpackPlugin is watching changes in the files. But it doesn't create render.php in the build folder, when the developer adds it in a src folder of a block. This PR Fixes the problem.

How?

  • renderPaths which is utilized to watch over all the render file paths, was not getting recalculated again during the watching process.
  • The patch adds code to the webpack.config.js in order to recalculate the paths whenever a **/*.php file's pattern is hit in the CopyWebPack Plugin of Webpack.
let renderPaths = getRenderPropPaths();
// CopyWebPack Plugin's Pattern
{
	from: '**/*.php',
	context: getWordPressSrcDirectory(),
	noErrorOnMissing: true,
	filter: ( filepath ) => {
		renderPaths = getRenderPropPaths(); 	// Recalculate Render Pro Paths
		return (
			process.env.WP_COPY_PHP_FILES_TO_DIST ||
			renderPaths.includes( filepath )
		);
	},
},

Testing Instructions

  1. Create a Dynamic Block, and don't add render.php file.
  2. Run the build/watch script, observe the build folder to see it reflect the src folder.
  3. Add render.php to render attribute of block.json of the Block.
  4. Create a render.php and see it doesn't get generated in the build folder of the Block.
  5. After Patch, It will get generated, when you add the render.php to src folder.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 25, 2023
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Takshil-Kunadia! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@gziolo gziolo added [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended labels May 29, 2023
@gziolo
Copy link
Member

gziolo commented Jun 1, 2023

I can confirm that it resolves the issue.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. I'll explore in the follow-up whether we can run the computation only once per change detected by webpack in watch mode.

@gziolo gziolo merged commit f43a7cb into WordPress:trunk Jun 1, 2023
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Congratulations on your first merged pull request, @Takshil-Kunadia! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 16.0 milestone Jun 1, 2023
sethrubenstein pushed a commit to pewresearch/gutenberg that referenced this pull request Jul 13, 2023
Co-authored-by: Takshil Kunadia <takshilkunadia@Takshils-MacBook-Air.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants