Make WordPress Core

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: westonruter's profile westonruter Owned by: westonruter's profile westonruter
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 @soyebsalar01
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 @ticket and @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 path and would not generate noise with the second _doing_it_wrong message.

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 );

#6 @westonruter
4 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 61416:

Script Loader: Warn when a registered style has invalid path data and allow inlining empty stylesheets.

When a stylesheet is registered with a path that does not exist or which is not readable, then a _doing_it_wrong() is now issued. Previously, paths that did not exist were silently skipped; paths for empty styles were also needlessly skipped, since wp_filesize() also returns 0 for the failure case.

Developed in https://github.com/WordPress/wordpress-develop/pull/10653

Follow-up to [50836].

Props westonruter, jonsurrell, soyebsalar01.
See #52620.
Fixes #64447.

Note: See TracTickets for help on using tickets.