Skip to content

Conversation

@youknowriad
Copy link
Contributor

Summary

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.

Changes

  • 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.

Trac Ticket

https://core.trac.wordpress.org/ticket/64393

Test Plan

  1. Set SCRIPT_DEBUG to true in wp-config.php
  2. Create a plugin using @wordpress/scripts
  3. Run wp-scripts start --hot
  4. Verify hot module replacement works when editing React components

🤖 Generated with Claude Code

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>
@github-actions
Copy link

github-actions bot commented Jan 13, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props youknowriad, wildworks, manzoorwanijk.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@youknowriad
Copy link
Contributor Author

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.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@youknowriad
Copy link
Contributor Author

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.

@youknowriad youknowriad requested a review from t-hamano January 13, 2026 10:33
@youknowriad
Copy link
Contributor Author

@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.

Copy link
Contributor

@t-hamano t-hamano left a 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?

cc @manzoorwanijk @jsnajdr @aduth

Comment on lines +41 to +45
// 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',
Copy link
Member

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?

Copy link
Member

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 ) {
Copy link
Member

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)?

Copy link
Contributor Author

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.

Copy link
Member

@manzoorwanijk manzoorwanijk Jan 15, 2026

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.

Copy link
Contributor Author

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.

@youknowriad
Copy link
Contributor Author

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.

Copy link
Member

@jsnajdr jsnajdr left a 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.

@youknowriad
Copy link
Contributor Author

This was committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants