Repository navigation
Fixed lazy-load gradient background images - #1212
Conversation
There was a problem hiding this comment.
🔵 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—noteEvery callback onoptml_lazyload_bg_selectorsnow gets one more default selector. The ten callbacks ininc/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_selectorsfilter consumers, and the issue #1034 missing-image fatal error. - PHPUnit
Test_Bg_Selectoron 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
- Turn on lazy load and background lazy load in Optimole settings. Expected: both settings stay on after saving.
- 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.
- Open the page in a private window with the network panel open. Do not scroll. Expected: the background image is not requested.
- Scroll to the Quote block. Expected: the image loads and shows with the gradient.
- 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
| '[class*="wp-block-group"][style*="background-image"]', | ||
| // Gradient + image in one value: `linear-gradient(...), url(...)`. | ||
| '[style*="background-image"][style*="url("]', | ||
| ]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Not affected. The #1034 fix (41e456f) is the |
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 abackground-imagevalue, 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 existingbackground-image:url(watchers rather than replacing them, preserving compatibility with existing matching behavior.Closes #1203
Other information: