-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Scripts: Make React Fast Refresh work with multiple blocks #64924
Conversation
Size Change: 0 B Total Size: 1.83 MB ℹ️ View Unchanged
|
32b640e
to
4010850
Compare
Flaky tests detected in 3d031a4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12135432278
|
b024d2d
to
cf97a83
Compare
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
I tested and I was able to reproduce the lack of refresh using the published wp-scripts package.
When I built using the changes in this PR, refresh worked without issues.
…#64924) * Scripts: Make React Fast Refresh Work with multiple blocks * Properly pass the unique name for the build and updates test snapshots * Apply suggestions from code review * Add changelog entry Co-authored-by: gziolo <[email protected]> Co-authored-by: sirreal <[email protected]>
* Scripts: Make React Fast Refresh Work with multiple blocks * Properly pass the unique name for the build and updates test snapshots * Apply suggestions from code review * Add changelog entry Co-authored-by: gziolo <[email protected]> Co-authored-by: sirreal <[email protected]>
What?
Related to #25188.
Follow-up for #28273.
Related comments:
wp-scripts start --hot
works perfectly fine with a single entry point that contains all the logic used in the editor. It starts to break if multiple entry points get loaded in the project editor. A perfect example would be a plugin with numerous blocks where each of them loads JavaScript separately. The workaround so far was to bundle all JavaScript code for the editor together. However, it isn’t always the most efficient approach. Besides, it would be great if that worked out of the box, no matter how configured the entry points were.Screenshot from #25188 (comment):
Why?
Source: https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#component-not-updating-with-bundle-splitting-techniques
How?
In the development mode when React Fast Refresh is enabled, there is a shared runtime created. This way it acts as en entry point for existing scripts that orchestrates all updates with hot-module replacement for React code.
Known Issues
It looks like CSS support for hot-module reloading doesn't work anymore in
trunk
and with this branch. I will investigate this separately as it is unrelated to these changes. I found an issue that seems very similar webpack-contrib/mini-css-extract-plugin#1089. My debugging session pointed me in the direction thatmini-css-extract-plugin
is unable to correctly match the url of CSS file in thelink
tags with these coming from hot reload. The reason seems to originate from the fact that the asset version appended to the url confuses the plugin.Testing Instructions
Create a new test plugin with more than one block. You can do it as follows:
npx wp-create-block my-plugin --no-wp-scripts
.npx wp-create-block my-block --no-plugin
is helpful here.cd my-plugin ../node_modules/.bin/wp-scripts start --hot