-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Build/Test Tools: Restore React Refresh scripts for hot reloading #10725
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
Build/Test Tools: Restore React Refresh scripts for hot reloading #10725
Conversation
Restores the `wp_register_development_scripts()` function and associated build infrastructure to enable hot module replacement (HMR) when using `@wordpress/scripts` with the `--hot` flag. The React Refresh scripts were removed in [61438] as part of the Gutenberg build restructuring, but they are still needed for plugin developers using `wp-scripts start --hot` for block development. This commit: - Adds `react-refresh` and `@pmmmwh/react-refresh-webpack-plugin` npm dependencies - Creates `tools/webpack/development.js` to build the development scripts - Restores `wp_register_development_scripts()` in `script-loader.php` - Removes the deprecated stub from `deprecated.php` The scripts are only registered when `SCRIPT_DEBUG` is true and are not loaded during Core tests. Props youknowriad. Fixes #64393. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hot reloading has proven to be not very valuable in Gutenberg and WordPress in general since it's not a typical SPA. That said, this PR restores the previous behavior so we can make an informed decision about whether we still want it or not. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
I tested this with an example plugin, it works but I understand why no one really uses this, it's not the seamless experience that you get with SPAs. Anyone, we can see whether to commit or not this PR. |
|
@t-hamano What do you think we should do here? Maybe we can just merge this PR to restore previous status quo even if imperfect. |
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
There is WordPress/gutenberg#74618 to replace @pmmmwh/react-refresh-webpack-plugin with react-refresh. Perhaps we need to align the two PR approaches.
I was the first to suggest keeping hot reload, but is keeping react-refresh a major blocker to improving build tooling? If so, I'm starting to think that it might be a good time to remove all the hot-reload libraries and code now. What do you think?
| // React Refresh entry - injects runtime into global hook before React loads. | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.js' ]: | ||
| '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js', | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.min.js' ]: | ||
| '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have these in Gutenberg, why not use them from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have them only when we have the built files in build. But that's not always true. The webpack dev server serves files from memory, and needs to build the entire self-contained set of Gutenberg JS assets.
| * | ||
| * @param WP_Scripts $scripts WP_Scripts object. | ||
| */ | ||
| function wp_register_development_scripts( $scripts ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we backport this to Gutenberg to avoid 404 errors as mentioned in WordPress/gutenberg#74618 (comment)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need, this is only missing in WordPress trunk, which will get updated once this commit lands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't register those in Gutenberg to override the Core scripts. Which means that the ones in Gutenberg are never actually loaded. That is the reason I had to write Step 10 in the Testing Instructions in WordPress/gutenberg#74618 to load the scripts from Gutenberg to be able to test them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't register those in Gutenberg to override the Core scripts. Which means that the ones in Gutenberg are never actually loaded. That is the reason I had to write Step 10 in the Testing Instructions in WordPress/gutenberg#74618 to load the scripts from Gutenberg to be able to test them.
I think we should remove the ones in Gutenberg entirely.
|
My thinking is that we should ship this PR to "fix" things for folks using the previous version of wp-scripts but I won't be against removing this entirely from wp-scripts in Gutenberg. |
jsnajdr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 🙂
I wouldn't mind removing React Refresh completely. With esbuild it doesn't work at all. In npm run dev we would have to run our own dev server with esbuild.serve. We currently don't do that, we only recompile files in watch mode.
|
This was committed. |
Summary
Restores the
wp_register_development_scripts()function and associated build infrastructure to enable hot module replacement (HMR) when using@wordpress/scriptswith the--hotflag.The React Refresh scripts were removed in [61438] as part of the Gutenberg build restructuring, but they are still needed for plugin developers using
wp-scripts start --hotfor block development.Changes
react-refreshand@pmmmwh/react-refresh-webpack-pluginnpm dependenciestools/webpack/development.jsto build the development scriptswp_register_development_scripts()inscript-loader.phpdeprecated.phpThe scripts are only registered when
SCRIPT_DEBUGis true and are not loaded during Core tests.Trac Ticket
https://core.trac.wordpress.org/ticket/64393
Test Plan
SCRIPT_DEBUGtotrueinwp-config.php@wordpress/scriptswp-scripts start --hot🤖 Generated with Claude Code