Skip to content

feat: let an image keep its own sizes attribute - #1193

Merged
pirate-bot merged 3 commits into
developmentfrom
bugfix/1115
Oct 21, 2026
Merged

pirate-bot merged 3 commits into
developmentfrom
bugfix/1115

Conversation

@selul

@selul selul commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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 sizes attribute unless the value contains calc() or a similar formula. Sites with hand-written sizes had no supported way to keep them. This adds two opt-outs, neither of which needs a UI change:

  • Per image: an <img> with the data-optml-keep-sizes attribute keeps its sizes exactly as written. The new srcset candidates are still added, so the browser still gets the right files.
  • Site-wide: 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 sizes attribute 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:

  1. Enable the page profiler. Add data-optml-keep-sizes to an image with a custom sizes, and load the page on desktop and then on mobile so a profile exists.
  2. View the source: sizes is unchanged and srcset has the Optimole candidates.
  3. Remove the attribute and add the filter snippet instead: same result for every image.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?
Check Result
PHPUnit full suite (WP trunk, PHP 8.3) PASS, 431 tests
New tests in tests/test-srcset.php: attribute keeps sizes, filter keeps sizes, filter returning false overrides the attribute PASS
Mutation: drop the keep check all 3 new tests fail
PHP 7.4 lint, phpcs PASS

Not 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

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
@selul selul self-assigned this Oct 20, 2026
@selul
selul requested a review from pirate-bot October 20, 2026 20:24

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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… printed OK (3 tests, 6 assertions) (run R3)
  • The whole tests/test-srcset.php file passed at HEAD: cd /repo; set -o pipefail; timeout 600 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Srcset_Functionality::' 2… printed OK (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

Comment thread inc/tag_replacer.php
Comment thread tests/test-srcset.php Outdated
Comment thread tests/test-srcset.php
Comment thread readme.txt
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
@selul
selul requested a review from pirate-bot October 20, 2026 21:11

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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… printed OK (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::' -… printed OK (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
@selul
selul requested a review from pirate-bot October 20, 2026 21:31

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 &… printed Tests: 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… printed OK (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… printed OK (3 tests, 7 assertions) (run R1)
  • The whole srcset test class passed at f5c1078 in 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

@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for 2809bb4 is ready 🛎️!

@pirate-bot
pirate-bot merged commit 5a1421f into development Oct 21, 2026
20 checks passed
@pirate-bot
pirate-bot deleted the bugfix/1115 branch October 21, 2026 22:01
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.

3 participants