Opened 3 months ago
Closed 10 days ago
#63254 closed defect (bug) (fixed)
Introduce development mode for block editor styles
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8.2 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Editor | Keywords: | has-patch needs-dev-note fixed-major dev-feedback |
Focuses: | Cc: |
Description (last modified by )
When a block script is defined in the block.json
and registered automatically via register_block_script_handle()
the version is pulled from the script asset PHP file if it exists. This ensures that the cache is always busted when the file is updated.
Something similar should exist for register_block_style_handle
as otherwise it's a total pain to develop editor styles. I just lost a few hours this morning wondering why my styles didn't update even though I am using the @wordpress/scripts
package to recompile them on every change.
The answer was ultimately that the version is pulled from the block.json
's "version" property which doesn't change while building.
Replacing this:
$version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false; $result = wp_register_style( $style_handle_name, $style_uri, array(), $version );
with this:
$block_version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false; $version = SCRIPT_DEBUG ? filemtime( $style_path_norm ) : $block_version; $result = wp_register_style( $style_handle_name, $style_uri, array(), $version );
Should do the trick. The assets file is another option.
Attachments (2)
Change History (36)
#3
@
3 months ago
The change was first introduced in 56044 and mainly focused on performance improvements.
#6
@
3 months ago
That would be great to fix it. I think the logic should be unified between JS and CSS assets. Something like that should work best:
<?php $default_version = SCRIPT_DEBUG ? time() : false; $block_version = isset( $metadata['version'] ) ? $metadata['version'] : $default_version; $script_version = isset( $script_asset['version'] ) ? $script_asset['version'] : $block_version;
This would cover all possible cases including where the block.json
and script.asset.php
don't contain tje version
property. For styles, everything should look exactly the same but for the style asset when defined. However, it could be break down into two steps as today, reading style asset is not covered. The related issue is tracked in Gutenberg: https://github.com/WordPress/gutenberg/issues/56838.
#7
@
3 months ago
I wasn't sure if the script version updated if changes only happened to the scss. But if so, that sounds great to me.
#8
follow-up:
↓ 12
@
3 months ago
After taking a closer look, I think what @abcd95 provided is the best way to go forward. I extended that for scripts and script modules. The logic covers the case when the asset file doesn't contain version
which changes based on the file's content. In every other case when SCRIPT_DEBUG
is enabled the version should be randomized on every page load to ensure it never gets served from the cache.
This ticket was mentioned in PR #8725 on WordPress/wordpress-develop by @abcd95.
3 months ago
#11
#12
in reply to:
↑ 8
@
3 months ago
- Keywords needs-testing removed
Replying to gziolo:
After taking a closer look, I think what @abcd95 provided is the best way to go forward.
Thanks @gziolo for reviewing and @helgatheviking for testing the patch. I'm opening a PR to run and check the automated tests and making the review easier.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
3 months ago
#14
@
3 months ago
- Milestone changed from 6.8.1 to 6.8.2
In order to give this time for testing and to keep 6.8.1 focused on issues introduced during the 6.8 cycle or intentionally deferred at the end of the 6.8 cycle, I've moved this to 6.8.2
5 weeks ago
#15
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8725.diff
Environment
- OS: linux
- Web Server: Nginx
- PHP: 8.4.7
- WordPress: TRUNK
- Browser: Chrome
- Active Plugins: none
Actual Results
- ✅ Issue resolved with patch.
- ✅ CSS files now use filemtime() as version parameter when SCRIPT_DEBUG is enabled
- ✅ JS files also properly use filemtime() as version parameter when SCRIPT_DEBUG is enabled
- ✅ Cache busting works correctly - ?ver=xxx parameter changes with each file modification
- ✅ Block editor styles update immediately during development without manual cache clearing
Additional Notes
- Verified that both CSS and JS assets receive proper cache-busting timestamps
- Screenshots captured showing different ?ver=xxx values after file modifications
- Behavior only activates when SCRIPT_DEBUG is true, preserving production performance (version from block.json)
- No conflicts observed with existing block registration functionality
Supplemental Artifacts
Add as Attachment: Screenshots showing different version parameters for CSS and JS files
#16
@
5 weeks ago
- Keywords dev-feedback added
- Owner set to audrasjb
- Status changed from new to accepted
After testing the proposed PR during our agency's contribution day (see @whaze's comment above), it looks like this improvement is quite ready to ship, and it would be quite valuable in a block developer experience perspective. Further review welcome :)
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
4 weeks ago
#18
@
4 weeks ago
Reproduction Report
Description
This report validates whether the issue can be reproduced.
The issue relates to how block editor styles are cached. In development environments, style and script changes may not reflect immediately due to static versioning. The patch introduces timestamp-based versioning when SCRIPT_DEBUG
is enabled, allowing changes to reflect immediately without clearing the cache.
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 136.0.0.0
- OS: Linux
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Actual Results
- ✅ Error condition occurs (reproduced).
- Block editor assets are not cache-busted during development.
- Changes to SCSS/JS do not reflect unless cache is manually cleared.
Steps to Reproduce
- Check out the latest WordPress develop repo.
- Make sure that
define( 'SCRIPT_DEBUG', true );
is set. - Open a post in the Block Editor.
- Use browser DevTools to inspect block editor CSS/JS URLs.
- Confirm static
ver
is used (e.g.,ver=6.9-alpha...
) — indicating no cache-busting.
Additional Notes
- This behavior only applies when
SCRIPT_DEBUG
is enabled. - Useful in local development when iterating on block styles or scripts.
- On the JS side, some core files like
block-editor.js
editor.js
edit-post.js
already appear to include cache-busting based on the ver parameter and may not be affected by this patch.
Supplemental Artifacts
Current trunk:
#19
@
4 weeks ago
- Keywords needs-testing added
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8725
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 136.0.0.0
- OS: Linux
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Actual Results
- ❌ Issue not resolved with patch.
- Block-level styles and scripts continue to use static version strings like
ver=6.9-alpha-60093
even whenSCRIPT_DEBUG
is enabled. - DevTools inspection shows no timestamp-based cache busting for
style.css
oreditor-script.js
.
- Block-level styles and scripts continue to use static version strings like
Additional Notes
To pull and test the patch:
git fetch upstream pull/8725/head:pr-8725 git checkout pr-8725 npm install npm run build
SCRIPT_DEBUG
was defined.- Confirmed that the patch code matches both in the environment and the container. Check the screenshot below..
Supplemental Artifacts
✅ Confirmation of container code matched with https://github.com/WordPress/wordpress-develop/pull/8725/files#diff-8c99af92e4ec0fdb307ddd9b42be1e1ef1efe4a9f31287c23f346244dddd1ce9
#20
@
4 weeks ago
Sorry but in my case, the patch from https://github.com/WordPress/wordpress-develop/pull/8725 is not working. I might missed something else but I'm 100% sure I have same code base in my Docker container as per report above(In Supplemental Artifacts).
Hey @abcd95 @audrasjb - would mind to check https://core.trac.wordpress.org/ticket/63254#comment:19 and see if I'm doing it right? The block assets still using ver=6.9-alpha-60093-src even though I run build or dev. Maybe I'm looking on wrong files.
#21
follow-up:
↓ 22
@
4 weeks ago
@rollybueno thanks for the update. Can you share a zip file (or a github repo) containing the code of the custom block you tested with this patch?
#22
in reply to:
↑ 21
@
4 weeks ago
Oh! I was under the impression that the existing assets would automatically get a timestamp version in the ver parameter after pulling the PR and running the dev build, guess I got that wrong 😅
I'll go ahead and retest using the custom blocks. Thanks for the heads-up!
Replying to audrasjb:
@rollybueno thanks for the update. Can you share a zip file (or a github repo) containing the code of the custom block you tested with this patch?
#23
@
4 weeks ago
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Patch tested: Patch-8725.diff
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Firefox 139.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Custom Style Test Block
- Test Reports 1.2.0
Actual Results
- Before patch:
- Registered a custom block with editorStyle pointing to a compiled build/index.css
- Reloaded block editor without cache clear
- index.css loaded without timestamp versioning
- checkout the image
- After patch:
- ✅ The patch worked as expected
- ✅ Observed the CSS file now loads with ?ver=1750687743 based on filemtime()
- ✅ Edited editor.scss, performed npm run build and changes reflected as expected
- ✅ Confirmed via browser DevTools: version query param updates after each build
- ✅ checkout the image
#24
@
3 weeks ago
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8725
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Linux
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Block Development Boilerplate 0.1.0
- Test Reports 1.2.0
Actual Results
- ✅ Created a custom block using the official guide: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/
- ✅ Tested on trunk (before applying the patch) and confirmed the
ver
query parameter forstyle.css
did not use timestamp for cache-busting. - ✅ Applied the patch from https://github.com/WordPress/wordpress-develop/pull/8725, then ran
npm run env:stop
and restarted Docker to flush caching. - ✅ After restart, modifying the block correctly triggered a version bump in the
ver
query parameter. - ✅ The issue is no longer reproducible after applying the patch.
Additional Notes
- Restarting Docker after applying the patch was essential to invalidate cached data and properly confirm the fix.
- The patch ensures that block assets are properly cache-busted when a custom block is updated during development.
Supplemental Artifacts
TRUNK: You can clearly see here that the custom block ver
param is using Version value from plugin header, which in my case is 0.1.0
https://github.com/WordPress/wordpress-develop/pull/8725 - After checking out to this PR, restarting Docker, I can see the same plugin asset is now using cache-busting patch from this specific line of code: https://github.com/WordPress/wordpress-develop/pull/8725/files#diff-8c99af92e4ec0fdb307ddd9b42be1e1ef1efe4a9f31287c23f346244dddd1ce9R332
#26
@
3 weeks ago
Hey @audrasjb - apologies for the delayed feedback, I’ve only recently had the opportunity to investigate this more thoroughly. I can now confirm that the patch is working as expected based on my latest tests. Please disregard my earlier reproduction test. I’ve consolidated everything into the Test Report shared in comment:24, which includes a clear comparison of behavior before and after applying the patch.
I personally approve this patch 👍
#29
@
3 weeks ago
- Keywords fixed-major dev-feedback added; commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopened for 6.8.2 backport consideration.
Second committer sign-off required.
This ticket was mentioned in Slack in #core by zunaid321. View the logs.
13 days ago
#32
@
13 days ago
This ticket was brought up in a recent bug scrub.
Here's the feedback:
We are currently waiting for a second committer to push the ticket forward.
Hi @helgatheviking, Thanks for bringing this up.
I agree that the lack of automatic cache busting during development is problematic on many levels, especially when actively making styling changes and not seeing them reflected.
I will follow up with a proper patch; let me know if it tests well for you.