Scripts: Make React Fast Refresh work with multiple blocks#64924
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. |
sirreal
left a comment
There was a problem hiding this comment.
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 <gziolo@git.wordpress.org> Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
* 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 <gziolo@git.wordpress.org> Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
|
@gziolo Hey did you see the comment: fcee058#r150652268 It's still stopping me from using
The "editorScript": "file:./index.js",
"viewScript": "file:./view.js"and then in
With gutenberg/packages/scripts/config/webpack.config.js Lines 354 to 358 in b06588e This fixes it: const fields = getBlockJsonScriptFields( blockJson ) || {};Also, is it normal that the gutenberg/packages/dependency-extraction-webpack-plugin/lib/index.js Lines 392 to 397 in b06588e
Another change in
Is the Gutenberg part still the case? I usually develop without it and occasionally turn it on to check that what I have is "future-compatible" not vice versa. If Gutenberg has some logic for the "runtime" script then maybe that's what I'm missing, but for now I'll just enqueue it myself and seems to work with or without GB. |
No, I missed it.
Would you like to open PR with a bug fix proposed? You are 100% correct, this is one of the ways to address the case you explained when there are no scripts discovered.
No, it needs to get improved. Ideally, it should fallback to some other alternative way to get some more distinct name for the webpack build, or the name of the project defined in
It should get enqueued automatically, but there might be some more edge cases as it's nontrivial.
Gutenberg is no longer required. Where does this information come from? The logic for including the runtime is a mix of WordPress core code and the webpack build. First, webpack automatically injects the path to the runtime inside gutenberg/packages/scripts/config/webpack.config.js Lines 344 to 368 in 7a4b5aa In fact, this is where the bug you mentioned needs to be fixed. The code that registers the webpack runtime and other scripts defined for the block in |
What?
Related to #25188.
Follow-up for #28273.
Related comments:
wp-scripts start --hotworks 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
trunkand with this branch. I will investigate this separately as it is unrelated to these changes. I found an issue that seems very similar webpack/mini-css-extract-plugin#1089. My debugging session pointed me in the direction thatmini-css-extract-pluginis unable to correctly match the url of CSS file in thelinktags 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-pluginis helpful here.cd my-plugin ../node_modules/.bin/wp-scripts start --hot