You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scripts: npm run start does not load refreshed stylesheet into editor-canvas iframe, only head of main document #48448
I created an example block plugin via npx @wordpress/scripts create-block
then I changed into the new directory and ran npm run start
I added my new sample block into the editor to start playing around with it. And I noticed that the text was illegible due to inaccessible colors (dark gray text on a gray blue background)
I made a change to src/style.scss and the stylesheet was re-compiled.
But when I refreshed the editor page, nothing happened. In source the stylesheet still has a version of 0.1 which appears to be the style set in block.json as there's no enqueue_block_editor_assets anywhere to enqueue assets. Updating the version in block.jsonfinally forces the browser to refresh the stylesheet.
If that's intended behavior it's very counter to what I think npm run start is meant to do... put you in a developmental mode where everything updates as soon as you make a change..... even more so if you are attempting npm run start --hot and expecting hot reloading.
What is your proposed solution?
npm run start should enqueue a stylesheet based on the time it was last compiled... which I believe can already be found in build/index.asset.php and I as far as I can tell is used for the javascript files (as a change in src/edit.js) is immediately shown in the editor.
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
If you run npm run start it will just rebuild your assets which means...
In the frontend you see the changes after reload because the styles are injected in <style> tags which immediately reflects the changes.
In the backend however it calls your style.css file with your version from block.json attached to it. http://localhost/app/plugins/<pluginName>/build/accordion/index.css?ver=0.3.0
If you are not familiar with cache busting: the browser caches the file for you unless you hard reload (CTRL+SHIFT+R) or keep devtools open with the (no cache) option selected and normal reload. As soon as you change the block version the URL of this file changes and the browser thinks that this must be a new file because it looks different than before index.css?ver=0.3.1.
There are 2 other more developer friendly option you could implement which is: 1) your own webpack.config.js file where you define the output files with a unique contenthash included (see https://webpack.js.org/guides/caching/) or 2) use browsersync which reloads the page after file change through websockets with the new information.
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
As @Supportic mentioned above, you will need to clear the cache occasionally or follow one of the suggestions posted above. I personally use create-block all the time and just get in the habit of periodically clearing the cache.
I am going to close out this issue, but please feel free to reopen if you are experiencing any additional issues.
The frontend styles/scripts regenerate a version number on every file change (via the assets PHP file) which automatically busts the cache. The admin should have the same. It's a pain to clear the cache while developing the admin side. Please consider reopening.
changed the title [-]create-block followed by npm run start does not load refreshed stylesheet[/-][+]Scripts: npm run start does not load refreshed stylesheet due to lack of version change[/+]on May 19, 2023
To me it looks it's already loading style-index.css with a timestamp when index.scss is edited, so the caching should not be an issue and it's not caused by lack of version change.
The real issue here seems to be that it's loading the style-index.css?<timestamp> into the main document and not into the editor iframe document so it's never replacing the initial style loaded with the version from block.json.
Might be caused by not externalizing react-refresh. It's mentioned the troubleshooting there and it's also some more information in this issue.
Might be caused by not externalizing react-refresh.
It is externalized. That's necessary for making it work with the way WordPress enqueues scripts.
The real issue here seems to be that it's loading the style-index.css? into the main document and not into the editor iframe document so it's never replacing the initial style loaded with the version from block.json.
That sounds very likely to happen. I would recommend exploring that path further 👍
Yea, I debugged it in the inspector yesterday and observed that everything worked and change of index.scss trigged a full css reload, except I found the newly loaded correct style in the of the document and the initial loaded style was still there in the iframe. So pretty sure this is the issue.
Just ran into this issue again a year later. Is there anything I can do to nudge this along. I'm new to block dev, and having to clear the cache on my browser (which logs me out of my dev site) in order to test changes to editor styles is a very annoying barrier.
I looked a bit more into the issue, but couldn't find a way around it. Seems rather tricky. Think wp-scripts need to have an insert function for mini-css-extract-plugin that adds the linkTag both to the iframe and the head of the document.
But the insert function doesn't run because it can't find the chunkId and there are even testcases on mini-css-extract-plugin with this behavior. Might be a red herring, but because of this I couldn't get the insert function to run.
Could also be possible to just have a hack in your plugin that clones the link tags. I'm sure some block developers have fixed this somehow already as everyone developing using create-block can't be sitting reloading the page all the time, I hope 😕
Would also be good if someone changed the title of this bug. Should be something like: "npm run start does not load refreshed stylesheet into editor-canvas iframe, only head of main document"
changed the title [-]Scripts: npm run start does not load refreshed stylesheet due to lack of version change[/-][+]Scripts: npm run start does not load refreshed stylesheet into editor-canvas iframe, only head of main document[/+]on Feb 22, 2024
I left a comment in the Lightweight CSS extraction plugin repository webpack/mini-css-extract-plugin#1089 (comment) explaining the issues that prevent refreshing styles located in the iframe.
I don't know how everybody else is working around this because I keep running into this problem every time I touch block development.
The trac patch ensures a cache-busting version number when in development mode. The updated stylesheet is loaded on page refresh. I'm ok with not supporting hot reloading.. it would be nice, but personally I don't use it. The trac patch works great for me and I think it is a major improvement.
@helgatheviking, it would be great to fix it. Thank you for opening the ticket, I left my feedback there. I'm happy to help to bring it to the finish line.
@helgatheviking I know this is old, but thought it worth mentioning: the easiest way around this problem is to open your browser's developer tools and ensure that the "Disable Cache" is checked (in the network panel). And then just keep the dev tools open when you develop against the editor.
Activity
github-actions commentedon Mar 29, 2023
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
tomfinitely commentedon Mar 29, 2023
+1
Supportic commentedon Mar 29, 2023
If you run
npm run startit will just rebuild your assets which means...In the frontend you see the changes after reload because the styles are injected in
<style>tags which immediately reflects the changes.In the backend however it calls your
style.cssfile with your version from block.json attached to it.http://localhost/app/plugins/<pluginName>/build/accordion/index.css?ver=0.3.0If you are not familiar with cache busting: the browser caches the file for you unless you hard reload (CTRL+SHIFT+R) or keep devtools open with the (no cache) option selected and normal reload. As soon as you change the block version the URL of this file changes and the browser thinks that this must be a new file because it looks different than before
index.css?ver=0.3.1.There are 2 other more developer friendly option you could implement which is: 1) your own
webpack.config.jsfile where you define the output files with a unique contenthash included (see https://webpack.js.org/guides/caching/) or 2) use browsersync which reloads the page after file change through websockets with the new information.This might help #28273
github-actions commentedon Apr 30, 2023
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
ndiego commentedon May 2, 2023
As @Supportic mentioned above, you will need to clear the cache occasionally or follow one of the suggestions posted above. I personally use
create-blockall the time and just get in the habit of periodically clearing the cache.I am going to close out this issue, but please feel free to reopen if you are experiencing any additional issues.
helgatheviking commentedon May 2, 2023
The frontend styles/scripts regenerate a version number on every file change (via the assets PHP file) which automatically busts the cache. The admin should have the same. It's a pain to clear the cache while developing the admin side. Please consider reopening.
ndiego commentedon May 2, 2023
@helgatheviking of course, happy to reopen.
4 remaining items
[-]create-block followed by npm run start does not load refreshed stylesheet[/-][+]Scripts: npm run start does not load refreshed stylesheet due to lack of version change[/+]gorm commentedon Feb 11, 2024
To me it looks it's already loading
style-index.csswith a timestamp whenindex.scssis edited, so the caching should not be an issue and it's not caused by lack of version change.The real issue here seems to be that it's loading the
style-index.css?<timestamp>into the main document and not into the editor iframe document so it's never replacing the initial style loaded with the version from block.json.Might be caused by not externalizing react-refresh. It's mentioned the troubleshooting there and it's also some more information in this issue.
gziolo commentedon Feb 11, 2024
It is externalized. That's necessary for making it work with the way WordPress enqueues scripts.
That sounds very likely to happen. I would recommend exploring that path further 👍
gorm commentedon Feb 11, 2024
Yea, I debugged it in the inspector yesterday and observed that everything worked and change of index.scss trigged a full css reload, except I found the newly loaded correct style in the of the document and the initial loaded style was still there in the iframe. So pretty sure this is the issue.
gorm commentedon Feb 11, 2024
Maybe a result of the externalization then? pmmmwh/react-refresh-webpack-plugin#743
helgatheviking commentedon Feb 21, 2024
Just ran into this issue again a year later. Is there anything I can do to nudge this along. I'm new to block dev, and having to clear the cache on my browser (which logs me out of my dev site) in order to test changes to editor styles is a very annoying barrier.
gorm commentedon Feb 22, 2024
I looked a bit more into the issue, but couldn't find a way around it. Seems rather tricky. Think wp-scripts need to have an insert function for
mini-css-extract-pluginthat adds the linkTag both to the iframe and the head of the document.But the insert function doesn't run because it can't find the chunkId and there are even testcases on
mini-css-extract-pluginwith this behavior. Might be a red herring, but because of this I couldn't get the insert function to run.Could also be possible to just have a hack in your plugin that clones the link tags. I'm sure some block developers have fixed this somehow already as everyone developing using create-block can't be sitting reloading the page all the time, I hope 😕
Would also be good if someone changed the title of this bug. Should be something like: "npm run start does not load refreshed stylesheet into editor-canvas iframe, only head of main document"
[-]Scripts: npm run start does not load refreshed stylesheet due to lack of version change[/-][+]Scripts: npm run start does not load refreshed stylesheet into editor-canvas iframe, only head of main document[/+]gziolo commentedon Apr 16, 2025
I left a comment in the Lightweight CSS extraction plugin repository webpack/mini-css-extract-plugin#1089 (comment) explaining the issues that prevent refreshing styles located in the iframe.
helgatheviking commentedon Apr 16, 2025
I ran into this issue again (another year later :) ) and forgot I had posted this, so I opened a trac ticket: https://core.trac.wordpress.org/ticket/63254
I don't know how everybody else is working around this because I keep running into this problem every time I touch block development.
The trac patch ensures a cache-busting version number when in development mode. The updated stylesheet is loaded on page refresh. I'm ok with not supporting hot reloading.. it would be nice, but personally I don't use it. The trac patch works great for me and I think it is a major improvement.
gziolo commentedon Apr 18, 2025
@helgatheviking, it would be great to fix it. Thank you for opening the ticket, I left my feedback there. I'm happy to help to bring it to the finish line.
youknowriad commentedon Nov 18, 2025
We're moving away from @wordpress/scripts current build behavior towards
@wordpress/build, a more opinionated approach. See #72032 for more details.It doesn't support HMR yet though and would benefit from a dedicated issue for this.
jakeparis commentedon Sep 2, 2026
@helgatheviking I know this is old, but thought it worth mentioning: the easiest way around this problem is to open your browser's developer tools and ensure that the "Disable Cache" is checked (in the network panel). And then just keep the dev tools open when you develop against the editor.