#53375 closed defect (bug) (fixed)
Loading separate core block assets tries to load stylesheets on blocks that doesn't have styles
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Editor | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
In [51102] support for adding inline styles for all blocks was added, but this makes WP register styles to non-existing stylesheets.
Steps to replicate:
- Add
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
- Insert a block that dosn't have a block css. Ex. core/column.
- Visit the page and check the network tab to confirm that WP tries to load
/wp-includes/blocks/column/style.css
with status 404.
In Gutenberg this was fixed by adding false
url to blocks that dosn't have a stylesheet. See https://github.com/WordPress/gutenberg/pull/32275
Related: #53358
Attachments (2)
Change History (38)
This ticket was mentioned in PR #1362 on WordPress/wordpress-develop by walbo.
4 years ago
#1
- Keywords has-patch added
#2
@
4 years ago
- Component changed from General to Editor
- Milestone changed from Awaiting Review to 5.8
This ticket was mentioned in Slack in #core by chaion07. View the logs.
4 years ago
#4
@
4 years ago
- Keywords needs-testing added
Hi @walbo! Thank you for reporting this. We reviewed the ticket during a [recent bug-scrub session in Core]https://wordpress.slack.com/archives/C02RQBWTW/p1623702905385100. Based on the feedback from the team we feel the need for an owner to ensure that it gets to commit in the release cycle. The PR/patch seems good. Thanks!
Props to @JeffPaul
This ticket was mentioned in PR #1370 on WordPress/wordpress-develop by aristath.
4 years ago
#7
Backports https://github.com/WordPress/gutenberg/pull/32275
Trac ticket: https://core.trac.wordpress.org/ticket/53375
#8
@
4 years ago
Pushed an alternative patch on https://github.com/WordPress/wordpress-develop/pull/1370 backporting the Gutenberg tweaks. A followup will be pushed in Gutenberg to remove some file_exists
checks.
#9
follow-up:
↓ 11
@
4 years ago
Seeing file_exists
is used some other places in core as well so should maybe create a second ticket to explore removal of those.
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
4 years ago
#11
in reply to:
↑ 9
;
follow-up:
↓ 12
@
4 years ago
Replying to walbo:
Seeing
file_exists
is used some other places in core as well so should maybe create a second ticket to explore removal of those.
I haven't taken a deep dive into the other uses in Core, but this one happens within a loop through register_core_block_types_from_metadata()
. On brief glance, the other instances seem like one off file checks.
#12
in reply to:
↑ 11
@
4 years ago
Have tested the alternative PR from @aristath and it solves the issue. That PR removes one of the file_exists
.
#13
@
4 years ago
- Summary changed from Loading seperate core block assets tries to load stylesheets on blocks that dosn't have styles to Loading separate core block assets tries to load stylesheets on blocks that dosn't have styles
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
4 years ago
#15
@
4 years ago
- Keywords needs-testing removed
Testing
Env:
- OS: macOS Big Sur
- Browser: Firefox 89.0.1 and Chrome 91.0.4472.106
- PR 1370
Before applying the PR results:
Able to reproduce the reported problem as the following asset was requested in the browser (though it does not exist):
http://localhost:8889/wp-includes/blocks/column/style.css/?ver=5.8-beta2-51165-src
UPDATE:
I was not able to reproduce the 404 as my local test environment redirects it back to the root page. But the asset doesn't exist and should return 404. This specific problem is not related to the problem reported in this ticket and needs to be resolved separately.
After applying the PR results:
The nonexistent stylesheet was not requested.
Conclusion
Works as expected ✅
Removing the needs-testing
keyword.
#16
@
4 years ago
Code Review of PR 1370:
- Remove the loose implicit conditionals and replace with explicit conditional. My suggestion is to add a new variable called
$has_style_file
. See notes in the PR.
- @desrosj and I discussed
filemtime()
for non-core blocks.
I'm not seeing another dynamic way of setting a version number for these non-core blocks without checking the stylesheet's modification time. Non-dynamic ways would require adding a version to the metadata or opening the file and reading a version annotation (significantly less performant than filemtime
. IMO filemtime()
is the best route for dynamic versioning to ensure the browser requests the newest version of the non-core asset from the server.
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
4 years ago
hellofromtonya commented on PR #1370:
4 years ago
#19
Added some formatting comments that the core committer could take care of. Else, the patch looks good to me 👍
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#24
@
4 years ago
- Summary changed from Loading separate core block assets tries to load stylesheets on blocks that dosn't have styles to Loading separate core block assets tries to load stylesheets on blocks that doesn't have styles
#25
@
4 years ago
In my eyes, there are two good options and I don't know how realistic 1 of them is:
- Revert the entire feature
- Work to remove the
filemtime
before 5.8
Especially when using network based storage, this can be a slower than necessary operation and we should be aiming to keep the front end of the site as speedy as humanly possible.
#26
@
4 years ago
I've moved #53507 to the 5.8 milestone to investigate. As far as I can tell, the version
field in metadata is used already in register_block_script_handle()
. So I think we could try:
- Using this field if present in the metadata.
- Fall back to
false
ifversion
is not set. - Publish a dev note encouraging developers to always include a top level
version
field in thereblock.json
file.
#27
@
4 years ago
I agree that the filemtime
should be removed, but think the discussion should continue in #53507
The current patch doesn't add the filemtime
and fixes the issue described in the ticket.
#28
@
4 years ago
- Keywords commit removed
I was going to test this one more time and commit, but I'm now having trouble getting any individual style calls following the steps with add_filter( 'should_load_separate_core_block_assets', '__return_true' );
.
Ignoring the filemtime()
occurrence that we'll address in #53507, the changes in the PR definitely look like they are improvements to the underlying code. But I'd like to identify whether the original issue was fixed by another change before committing.
Can everyone retest with WP 5.8 beta4 to see if I'm missing something, or confirm that the issue was fixed?
#29
@
4 years ago
Still getting a GET http://localhost:8889/wp-includes/blocks/column/style.css?ver=5.8-beta4-51243-src net::ERR_ABORTED 404 (Not Found)
in trunk.
With the patch everything works as expected.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
4 years ago
#31
@
4 years ago
Here is a detailed steps to replicate after a request in slack:
- Create a new WordPress installation. I use
npm run env:start
in wordpress-develop. - Add
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
infunctions.php
. I have twenty twenty-one enabled. - Set permalinks to
Day and name
. (if not the file will return 301. See #53506) - Edit the hello world post. Insert columns. Select 50/50. Insert a paragraph in one of the columns.
- Save the post and visit the page frontend.
- Open the network and look for a 404 on
http://localhost:8889/wp-includes/blocks/column/style.css
#32
@
4 years ago
- Keywords commit added
Thanks @walbo! I'm not sure which step I was missing before, but I am seeing this now.
Going to commit the fix.
4 years ago
#34
Merged into Core in https://core.trac.wordpress.org/changeset/51254.
#36
@
4 years ago
I've opened https://github.com/WordPress/gutenberg/pull/33075 to discuss moving forward with using and encouraging version in block.json in a more organized way.
Trac ticket: https://core.trac.wordpress.org/ticket/53375