Skip to content

fix(assets): never require a non-script asset, hash every non-enqueued file - #513

Merged
oxyc merged 1 commit into
masterfrom
fix/assets-helper-canonical
Dec 2, 2026
Merged

oxyc merged 1 commit into
masterfrom
fix/assets-helper-canonical

Conversation

@oxyc

@oxyc oxyc commented Dec 2, 2026

Copy link
Copy Markdown
Member

Makes this the canonical Assets.php before copying it to the sites, whose copies have drifted into about ten versions. It keeps this copy's child-theme manifest support and takes the two real fixes that only some copies have.

Changes

  • dependencies() on a non-script path. The .js → .asset.php swap was a regex, so for a .css (or any other) path it matched nothing and required the asset itself, echoing it into the response. It now returns [] for anything that isn't .js.
  • uri() cache-busting. ?v=<hash> was appended only under images/ and svgs/, so fonts, components and anything else the manifest hashes went out unbusted. It now busts every manifest entry except .js and .css, which wp_enqueue_* versions with ?ver= (busting them here too would emit ?v=…&ver=…).

Left out on purpose

Several copies change version() to return false instead of '', commented "WordPress treats an empty string as print no ?ver= at all". That's not what core does: WP_Scripts/WP_Styles treat any empty non-null version ('' or false) the same and fall back to the default version; only null drops ?ver=. So it's a no-op and stays as is.

Review

  • Today's callers here are unaffected: dependencies() is only called on .js entries, and the only non-script uri() is images/default-teaser.webp, which was already busted.
  • php -l and Pint pass. No unit tests cover Assets.

🤖 Generated with Claude Code

…d file

dependencies() swapped .js for .asset.php with a regex; for any other path
the regex matched nothing and the asset itself was require'd, echoing a
stylesheet into the response. Only scripts have a sibling .asset.php.

uri() only appended ?v= under images/ and svgs/, so fonts, components and
anything else the manifest hashes went out unbusted. Bust everything except
scripts and stylesheets, which wp_enqueue_* versions with ?ver=.

Both fixes already run on the wp-gds-theme sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oxyc
oxyc merged commit b3900e8 into master Dec 2, 2026
@oxyc
oxyc deleted the fix/assets-helper-canonical branch December 2, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant