Skip to content

Fixed lazy-load gradient background images - #1212

Merged
pirate-bot merged 1 commit into
developmentfrom
bugfix/1203
Oct 31, 2026
Merged

pirate-bot merged 1 commit into
developmentfrom
bugfix/1203

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Fixed lazy loading for background images by adding a default watcher, [style*="background-image"][style*="url("], that detects images anywhere in a background-image value, including when combined with gradients. This restores the hide rule and lazy-load observer for blocks such as Quote, Pullquote, Verse, Post Content, and Accordion, preventing background images from downloading immediately. The fix was applied alongside the existing background-image:url( watchers rather than replacing them, preserving compatibility with existing matching behavior.

Closes #1203

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?

@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for beefea0 is ready 🛎️!

@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.

🔵 Needs a closer look

QA check: The new watcher and its tests pass, but the lazy-load script's behavior on a gradient block was not exercised in a browser.

  • inc/lazyload_replacer.php:141 — note Every callback on optml_lazyload_bg_selectors now gets one more default selector. The ten callbacks in inc/compatibilities/ only append and return, so they are safe. A callback in another plugin or theme that removes or replaces defaults by array position would now change the wrong selector. Please confirm that no known integration indexes this list by position. If none does, the change is safe. If one does, its lazy-load rules break.
Validation details
  • Files reviewed: 2/2 changed files. Two question rows stayed unchecked: the optml_lazyload_bg_selectors filter consumers, and the issue #1034 missing-image fatal error.
  • PHPUnit Test_Bg_Selector on PHP 8.3 passed at HEAD with 25 tests.
  • The same tests on the base code failed both gradient data sets with Failed asserting that false is true.
  • A source read showed that the hide rule and the script selectors include the new watcher.
QA steps
  1. Turn on lazy load and background lazy load in Optimole settings. Expected: both settings stay on after saving.
  2. On WordPress 7.1, create a page with a tall spacer, then a Quote block with a background image and a gradient. Expected: the page saves.
  3. Open the page in a private window with the network panel open. Do not scroll. Expected: the background image is not requested.
  4. Scroll to the Quote block. Expected: the image loads and shows with the gradient.
  5. Repeat with a Quote block that has only a background image. Expected: the same lazy behavior.
Untested areas
  • The filter consumers row was not settled for code outside this repository.
  • The issue #1034 missing-image row was not exercised on PHP 8.2+.
  • The external lazy-load script was not run, because it is not in the repository.

🤖 Automated review · run code-review-agent_6ae314c5d6ff87.69599475.


🤖 Review agent — review posted ✅ on beefea07 · commented · 0 findings · 25 min

Run code-review-agent_6ae314c5d6ff87.69599475 · trail

Comment thread inc/lazyload_replacer.php
'[class*="wp-block-group"][style*="background-image"]',
// Gradient + image in one value: `linear-gradient(...), url(...)`.
'[style*="background-image"][style*="url("]',
];

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.

note Issue #1034 was a fatal error in this file on PHP 8.2+ when an image is missing from uploads. The change adds only one selector string and does not touch that path. Please confirm that a page with an offloaded or deleted image still renders on PHP 8.2+ with lazy load on. A normal page means safe. A fatal error means the earlier fix regressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Safe. The new selector is appended after the existing defaults, so they keep positions 0–5. Only the site's custom selectors move down by one, and their positions already vary from site to site, so nothing can depend on them. All 10 callbacks in inc/compatibilities/ just append and return. No other plugin or theme in this install hooks the filter.

@girishpanchal30

Copy link
Copy Markdown
Contributor Author

@pirate-bot

inc/lazyload_replacer.php:141 — note Every callback on optml_lazyload_bg_selectors now gets one more default selector. The ten callbacks in inc/compatibilities/ only append and return, so they are safe. A callback in another plugin or theme that removes or replaces defaults by array position would now change the wrong selector. Please confirm that no known integration indexes this list by position. If none does, the change is safe. If one does, its lazy-load rules break.

Not affected. The #1034 fix (41e456f) is the is_array( $sizes ) guard in get_svg_for(), which builds image placeholders. This PR only adds one string to the $default_watchers array in get_background_lazyload_selectors(), a separate method that never reads image sizes. The full PHPUnit suite (469 tests) passes on PHP 8.4 with the change.

@pirate-bot
pirate-bot merged commit c17c07d into development Oct 31, 2026
14 checks passed
@pirate-bot
pirate-bot deleted the bugfix/1203 branch October 31, 2026 12:03
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.

2 participants