Opened 4 months ago
Closed 4 months ago
#64447 closed defect (bug) (fixed)
Invalid path data for registered stylesheets silently fails in wp_maybe_inline_styles()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | 5.8 |
| Component: | Script Loader | Keywords: | has-patch has-unit-tests |
| Focuses: | css, performance | Cc: |
Description
Stylesheets may be inlined when they have path data added which indicates where the stylesheet can be located on the filesystem. See [50836] for #52620. However, if the path is invalid then the inlining will silently fail as if the path wasn't provided in the first place. What is missing is _doing_it_wrong() to alert the developer that the path is incorrect. Otherwise, they may never discover there is an issue, and they may be confused why inlining isn't happening.
Change History (6)
This ticket was mentioned in PR #10653 on WordPress/wordpress-develop by @westonruter.
4 months ago
#1
- Keywords has-patch has-unit-tests added
@westonruter commented on PR #10653:
4 months ago
#2
Tests are failing due to the GHA runner not having the built assets.
#3
@
4 months ago
I tested, Without the patch an invalid path causes wp_maybe_inline_styles() to fail silently.
With patch applied, _doing_it_wrong is triggered correctly.
@westonruter commented on PR #10653:
4 months ago
#4
Gemini 3 review:
The changes look solid and follow WordPress core coding standards:
- Logic: The handling of empty files versus missing files is now explicit.
- Error Handling: Appropriate
_doing_it_wrong()calls have been added for missing files. - Indentation: Verified that tabs are used consistently for indentation.
- Testing: New tests cover the edge cases (bad path with fake size, good path with zero size) and verify that incorrect usage is triggered when expected.
- Documentation: Proper JSDoc/PHPDoc tags are used, including
@ticketand@covers.
No issues found. Everything looks ready for commit.
@westonruter commented on PR #10653:
4 months ago
#5
$style['path']is a way for styles to opt-in to this inlining. Is that correct?
Presumably, styles that aren't locally available would not add
pathand would not generate noise with the second_doing_it_wrongmessage.
That is correct. This is how styles can opt in to inlining. IMO, this could be made automatic by looking at the URL. But for now the path is how this is done. See dev note:
Internally, only assets that have data for path defined get processed, so to opt-in, a stylesheet can add something like this:
wp_style_add_data( $style_handle, 'path', $file_path );
Trac ticket: https://core.trac.wordpress.org/ticket/64447