Repository navigation
feat: let an image keep its own sizes attribute - #1193
Conversation
The page profiler adds its measured breakpoints to an image's sizes attribute unless the value contains calc() or a similar formula. Sites with hand-written sizes had no supported way to keep them. An image with data-optml-keep-sizes now keeps its existing sizes attribute (srcset candidates are still added). The optml_keep_existing_sizes filter does the same site-wide without changing the markup. Refs #1115 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
There was a problem hiding this comment.
🟡 Changes requested
The keep-sizes opt-out works in tests, but a log message, the FAQ and two tests need fixes.
Validation details
- Files reviewed: 4/4 changed files.
- PHPUnit 9.6.22 on PHP 8.3.35 ran the three new tests at HEAD:
cd /repo; set -o pipefail; timeout 600 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Srcset_Functionality::tes…printedOK (3 tests, 6 assertions)(run R3) - The whole
tests/test-srcset.phpfile passed at HEAD:cd /repo; set -o pipefail; timeout 600 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Srcset_Functionality::' 2…printedOK (65 tests, 162 assertions)(run R2) - On the pr-base code, the attribute test and the filter test fail. The no-existing-sizes test passes. This base run has no run record.
- Source checks found no other profiler path that rewrites
sizes. The new debug log uses a defined$new_url.
Untested areas
- A live page with a stored page profile was not exercised.
- Jest and Playwright suites were not run, because no JavaScript changed.
🤖 Automated review · run code-review-agent_6ad7ce01d088c1.35057220.
🤖 Review agent — review posted ✅ on b72563f1 · changes requested · 4 findings · 14 min
Run code-review-agent_6ad7ce01d088c1.35057220 · trail
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
There was a problem hiding this comment.
🟡 Changes requested
Three earlier findings are fixed, but the new filter-override test still passes without this change. See #1193 (comment).
Validation details
- Files reviewed: 4/4 changed files.
- PHPUnit 9.6.22 on PHP 8.3.35 ran the three keep tests at HEAD:
set -o pipefail; sandbox-doctor.sh 2>&1 | grep -E 'FAIL|OK' | head -20; cd /repo; set -o pipefail; timeout 300 vendor/bi…printedOK (3 tests, 6 assertions)(run R2) - The whole srcset test class passed at HEAD:
cd /repo; set -o pipefail; timeout 300 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Srcset_Functionality::' -…printedOK (65 tests, 162 assertions)(run R3) - No code or test reads the old debug message text. The only log listener prints the message.
Untested areas
- A live page with a stored page profile was not exercised. The sandbox web server was down.
- The base-tree test run has no run record. The override test claim rests on source reading.
🤖 Automated review · run code-review-agent_6ad7d8f9c95662.04542143.
🤖 Review agent — review posted ✅ on f5c1078d · changes requested · 0 findings · 9 min
Run code-review-agent_6ad7d8f9c95662.04542143 · trail
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
There was a problem hiding this comment.
🟢 Approved
The PR passes: the filter-override test now fails without this change, and every earlier finding is fixed.
Validation details
- Files reviewed: 4/4 changed files. The only commit since the last review changes
tests/test-srcset.php. - With pr-base production files, the override test fails:
set -o pipefail; B=/workspace/checks/C1/base-tree; rm -rf $B; mkdir -p $B; cd /repo && git archive HEAD | tar -x -C $B &…printedTests: 1, Assertions: 1, Failures: 1(run R2) - At HEAD, the override test passes:
set -o pipefail; cd /repo && vendor/bin/phpunit --do-not-cache-result --filter 'Test_Srcset_Functionality::test_keep_exi…printedOK (1 test, 2 assertions)(run R3) - At HEAD, the three keep tests pass:
cd /repo && set -o pipefail; vendor/bin/phpunit --do-not-cache-result --filter 'test_keep_' 2>&1 | tee /workspace/checks…printedOK (3 tests, 7 assertions)(run R1) - The whole srcset test class passed at
f5c1078in run code-review-agent_6ad7d8f9c95662.04542143, not rerun. No production file changed since.
Untested areas
- A live page with a stored page profile was not exercised. The sandbox web server was not served.
🤖 Automated review · run code-review-agent_6ad7dd9caa50e7.10252505.
🤖 Review agent — review posted ✅ on 2809bb46 · approved · 0 findings · 6 min
Run code-review-agent_6ad7dd9caa50e7.10252505 · trail
Requested by Marius · project thread
All Submissions:
Changes proposed in this Pull Request:
Closes #1115.
The page profiler adds its measured breakpoints to an image's existing
sizesattribute unless the value containscalc()or a similar formula. Sites with hand-writtensizeshad no supported way to keep them. This adds two opt-outs, neither of which needs a UI change:<img>with thedata-optml-keep-sizesattribute keeps itssizesexactly as written. The newsrcsetcandidates are still added, so the browser still gets the right files.add_filter( 'optml_keep_existing_sizes', '__return_true' );does the same for every image without changing the markup. The filter also receives the tag, so a site can choose which images it applies to.An image without a
sizesattribute still gets the generated one, because there's nothing to keep. The readme FAQ documents both options.How to test the changes in this Pull Request:
data-optml-keep-sizesto an image with a customsizes, and load the page on desktop and then on mobile so a profile exists.sizesis unchanged andsrcsethas the Optimole candidates.Other information:
tests/test-srcset.php: attribute keeps sizes, filter keeps sizes, filter returning false overrides the attributeNot proven: a live page with the profiler. Codex review was skipped because the Codex CLI isn't available in this environment.
Generated by Claude Code