Repository navigation
Conversation
With Retina images on, the page profiler stores a 1x and a 2x entry per breakpoint. The 2x entry carries its delivered width (e.g. 824, advertised as "824w") and dpr 2, and the CDN multiplies w by dpr, so the URL asked for w:824/dpr:2 and delivered 1648px for an 824w candidate (#1111). The sizes attribute also used that doubled width, so a breakpoint got two max-width conditions, one with the 2x width (#1113). The URL now asks for the CSS width (width / dpr) with the dpr, and the sizes slot uses the CSS width, so the 1x and 2x entries give the same condition and array_unique() keeps one. Doing this in PHP also corrects profiles already stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues: #1111, #1113
With Retina images on, the page profiler's 2x srcset candidates delivered twice their advertised width, and the
sizesattribute got a second, doubled condition for the same breakpoint. Both came from the same value: the 2x entry carries its delivered width (for example 824, advertised as824w) together withdpr: 2, and that width was used both as the URL'swand as thesizesslot.What changed
Optml_Tag_Replacer::add_missing_srcset_attributes()— for an entry withdpr > 1, the CSS width iswidth / dpr:w:412/dpr:2), because the CDN multiplieswbydpr. This is the same convention the plugin already uses for its otherdpr:2/2xsources. The824wcandidate now delivers 824px instead of 1648px (Profiled width candidates can deliver twice their advertised intrinsic width with Retina Quality #1111);sizesslot is the CSS width, so the 1x and 2x entries give the same condition andarray_unique()keeps one (Generated sizes attribute can contain duplicate max-width conditions #1113).Note
Only sites with Retina images on (off by default) and only profiler-generated 2x candidates are affected. Their URLs change once, so the CDN fetches those variants again. Fixing it in PHP also corrects the profiles already stored (they last up to 7 days), with no JS change.
Not in this PR: when a page already has a
sizesattribute,enhance_existing_sizes()sorts the merged conditions by breakpoint descending, so the firstmax-widthcondition matches every smaller viewport and the rest are never used. That changessizeson most profiled pages and deserves its own issue.Tests
tests/test-srcset.php: with Retina on, a 2x entry's URL isw:412/dpr:2/h:300 … 824w(now:824); two breakpoints with 1x and 2x entries give one condition each,(max-width: 480px) 300px, (max-width: 768px) 412px. Both fail ondevelopment. Mutations (URL orsizeswith the delivered width, height not divided) each fail a test.QA
Turn on Retina images in
WP Admin → Optimole → Settings, and keep the page profiler on.Open a page with large content images on a desktop browser, then reload it once the profile is stored.
View the source of an image that got a generated
srcset.Expect: each
2x-sized candidate URL hasw:<half the descriptor>/dpr:2(for examplew:412/dpr:2 … 824w), andsizeshas onemax-widthcondition per breakpoint.Verification (head
335e1b4d)tests/test-srcset.phprun alonedevelopmentsourcephpcs,phpstan(build-only include errors excluded locally; CI builds assets first)Not proven
dpr:2/2xusage).🤖 Generated with Claude Code