Skip to content

Scripts: Prevent react-refresh/runtime from being externalized in HMR mode#78498

Open
theritiktiwari wants to merge 3 commits into
WordPress:trunkfrom
theritiktiwari:fix/hmr-issue
Open

Scripts: Prevent react-refresh/runtime from being externalized in HMR mode#78498
theritiktiwari wants to merge 3 commits into
WordPress:trunkfrom
theritiktiwari:fix/hmr-issue

Conversation

@theritiktiwari
Copy link
Copy Markdown

What?

Closes #77293

Prevent react-refresh/runtime from being externalized by DependencyExtractionWebpackPlugin during HMR mode.

This ensures the generated *.asset.php file does not include the wp-react-refresh-runtime dependency, which is not registered by WordPress and causes block scripts to fail in development mode.

Why?

When running block development with HMR (npx wp-scripts start --hot), ReactRefreshWebpackPlugin injects and manages react-refresh/runtime internally.

However, DependencyExtractionWebpackPlugin was externalizing this runtime dependency and generating:

'dependencies' => array(
    ...
    'wp-react-refresh-runtime',
)

Since WordPress never registers a corresponding wp-react-refresh-runtime script handle, the editor attempts to enqueue a missing dependency, causing the block script to fail to load during development.

This issue only affects HMR/development mode.

How?

Pass a custom requestToExternal override to DependencyExtractionWebpackPlugin when React Fast Refresh is enabled. The override prevents react-refresh/runtime from being externalized. This keeps the runtime managed entirely by ReactRefreshWebpackPlugin and prevents invalid WordPress script dependencies from being generated.

Testing Instructions

  1. Create a block plugin using @wordpress/create-block.
  2. Start the development server in HMR mode.
  3. Open the block editor.
  4. Before applying this PR, inspect the generated *.asset.php file and observe wp-react-refresh-runtime inside the dependencies array.
  5. Apply this PR and rebuild/start again.
  6. Verify the generated *.asset.php file no longer includes wp-react-refresh-runtime.
  7. Confirm the block loads correctly in the editor without missing script dependency errors.

Testing Instructions for Keyboard

  1. Open the block editor using the keyboard only.
  2. Insert the test block.
  3. Verify the editor loads correctly and the block is usable.
  4. Confirm there are no missing dependency errors preventing interaction.

Use of AI Tools

Used GH Copilot for assistance with debugging, and drafting PR documentation.

@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @daniDevKr.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: daniDevKr.

Co-authored-by: theritiktiwari <theritiktiwari@git.wordpress.org>
Co-authored-by: karthikeya-io <karthikeya01@git.wordpress.org>

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

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 21, 2026
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @theritiktiwari! In case you missed it, we'd love to have you join us in our Slack community.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The block is not visible in the editor after that the "wp-scripts start --hot" command is launched

1 participant