Skip to content

Build/Test Tools: Fix React Refresh hot reloading for block plugins#10757

Closed
youknowriad wants to merge 1 commit intoWordPress:trunkfrom
youknowriad:fix/react-refresh-hot-reload
Closed

Build/Test Tools: Fix React Refresh hot reloading for block plugins#10757
youknowriad wants to merge 1 commit intoWordPress:trunkfrom
youknowriad:fix/react-refresh-hot-reload

Conversation

@youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Jan 19, 2026

Trac Ticket

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

Summary

  • Fixes hot reloading (HMR) not working for block plugins when using @wordpress/scripts with the --hot flag
  • Root cause: react-refresh-entry.js was bundling its own copy of react-refresh/runtime instead of using window.ReactRefreshRuntime, creating two separate runtime instances
  • Fix: Split webpack development config into two configs - one for runtime (creates the global) and one for entry (uses it as external)

Test plan

  1. Create a test block plugin: cd src/wp-content/plugins && npx @wordpress/create-block test-block
  2. Activate the plugin
  3. Start hot reload: cd src/wp-content/plugins/test-block && npm run start -- --hot
  4. Open the block editor and add the Test Block
  5. Edit src/edit.js - changes should appear automatically without page refresh

🤖 Generated with Claude Code

@github-actions
Copy link

github-actions bot commented Jan 19, 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, manzoorwanijk, wildworks.

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

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

Comment on lines +84 to +87
[ 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.

TBH, this react refresh entry has nothing to do with Webpack. It works without that over-complication done by this plugin, increasing the bundle size needlessly.

We could explore replacing it directly with react-refresh which it depends upon anyway, just like in WordPress/gutenberg#74618

Copy link
Contributor Author

@youknowriad youknowriad Jan 20, 2026

Choose a reason for hiding this comment

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

@manzoorwanijk Please consider exploring that if you think it's important. The main goal is here is not to change behavior but to restore a working state. Do you think that solution would be something easy to implement without wp-scripts change.

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.

In my testing, it works fine even when I activate the nightly version of the Gutenberg plugin.

@youknowriad youknowriad force-pushed the fix/react-refresh-hot-reload branch from fd7c81b to c56c797 Compare January 28, 2026 10:16
The `react-refresh-entry.js` script was bundling its own copy of
`react-refresh/runtime` instead of using the `window.ReactRefreshRuntime`
global set up by `react-refresh-runtime.js`. This created two separate
runtime instances: the entry script set up hooks on its bundled copy, while
plugins called `performReactRefresh()` on the window global — a different
instance with no hooks registered.

This splits the development webpack config into two configs so that
`externals` only applies to the entry script. The runtime config bundles
`react-refresh/runtime` and exposes it as `window.ReactRefreshRuntime`,
while the entry config uses that global as an external.

Follow-up to [61488].

Props youknowriad.
See #64393.
@youknowriad youknowriad force-pushed the fix/react-refresh-hot-reload branch from c56c797 to 97daf5b Compare January 28, 2026 10:18
@youknowriad
Copy link
Contributor Author

This was committed

@youknowriad youknowriad deleted the fix/react-refresh-hot-reload branch January 28, 2026 10:28
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.

3 participants