Missing-srcset enhancement rewrites data-*-srcset attributes and breaks Envira lazy-load placeholders
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Status (2026-10-16)
Fixed in PR #1185 (bugfix/1184 → development). Pirate-bot approved f38d4978, and all checks are green.
- The srcset/sizes enhancement now reads the image tag attribute by attribute, the way a browser does. It only reads and writes the image's own quoted
src/srcset/sizes, at their exact positions;data-*-srcset,data-src,data-sizesand text inside other values are never touched. - An image whose first
srcorsrcsetis adata:placeholder (quoted, unquoted, spaced or uppercase) is left to its lazy loader, including itssizes. This covers the QA agent's finding. - Verified on
testing.optimole.com/envira-test-page/: gallery 92 image 4 keeps Envira's placeholdersrcset, with no duplicatesizes. The Firefox Envira E2E test passes on the PR. - A differential run against
development(124 cases through the full replacer) changed no CDN URL replacement. Onlysrcset/sizesdiffer, in 2 cases. - Not enhanced any more (they keep their CDN
src): malformed markup such asalt=can't, and partly JSON-escaped markup (src="https:\/\/…"). - Not changed: when an image's own
srcsetusesxdescriptors, addingwentries still mixes them; repeatedsizesbreakpoints remain the #1111 / #1113 area. - The second QA run found that an image with a
data:placeholder indata-srcbefore its realsrcgets no profiler srcset, ondevelopmenttoo. The image parser takes the placeholder as the image URL; filed separately as #1186. development(and the release PR #1169) keep failing this E2E test until #1185 is merged.
Summary
When the page profiler has missing-srcset data for an image, Optml_Tag_Replacer::add_missing_srcset_attributes() rewrites the wrong attributes. Its srcset= / sizes= / src= regexes are not anchored to an attribute name, so they also match data-*-srcset, data-*-sizes and data-*-src attributes that lazy-load and gallery plugins use.
On Envira Gallery images this:
- reads the existing value from
data-envira-srcset(the first match) instead ofsrcset; - writes the merged value into every match, so Envira's placeholder
srcset="data:image/gif;base64,…"is replaced with real CDN candidates; - inserts
sizesafter both the real and thedata-envira-srcsetattribute, so the tag ends up with twosizesattributes; - mixes
xandwdescriptors in onesrcset(… 2x, … 254w, … 400w), which is invalid.
Because the placeholder srcset is gone, the browser downloads the image immediately instead of leaving it to Envira's lazy loader. In Firefox that load finishes before Envira's justifiedGallery init, and the init then resets src to data-safe-src (the GIF placeholder). The image still shows (from srcset), but the markup no longer matches what the gallery script expects, and lazy loading is defeated for that image.
Steps to reproduce
- Envira Gallery Lite gallery on a page, Optimole connected, lazy load in viewport mode.
- Visit the page so
optimizer.jsstores a missing-srcset measurement for one gallery image (the profile inOptml_Manager::instance()->page_profiler). - Reload and look at that image's tag.
Live example: http://testing.optimole.com/envira-test-page/, gallery 92, attachment 18 (#envira-gallery-wrap-92 #envira-gallery-image-18).
Expected: srcset keeps Envira's data: placeholder, data-envira-srcset is not touched, one sizes attribute.
Actual:
<img … class="envira-gallery-image envira-gallery-image-4 envira-normal envira-lazy"
src="https://….i.optimole.com/…/w:254/h:300/…/marina-mazur-…-scaled.jpg"
data-envira-srcset="… 2x, … 254w, … 400w" sizes="(max-width: 2560px) 254px"
srcset="… 2x, … 254w, … 400w" sizes="(max-width: 2560px) 254px"
data-safe-src="data:image/gif;base64,…" />
The other images in the same gallery (no profiler data) keep srcset="data:image/gif;base64,…".
Impact
- The E2E check
tests/e2e/envira.spec.ts › Gallery images all attributes replaced properlyhas failed on Firefox on 7 of the last 8developmentruns since 2026-10-12, including the release PR #1169. It started once the shared QA site's profile recorded missing-srcset data for attachment 18. Chromium passes only because its script timing is different. - Any plugin that keeps the real source in a
data-*-srcset/data-*-srcattribute (Envira, other galleries and lazy loaders) can get duplicated attributes or a placeholdersrcsetreplaced with eager candidates.
Root cause
inc/tag_replacer.php:
add_missing_srcset_attributes():strpos( $tag, 'srcset=' )/strpos( $tag, 'sizes=' )presence checks; srcset insert after/(src=["'][^"']*["'])/i; sizes insert after/(srcset=["'][^"']*["'])/i; existing-sizes lookup/sizes=…/.enhance_existing_srcset()/enhance_existing_sizes():preg_matchon/srcset=…/and/sizes=…/, thenpreg_replacewith no limit.
The code was introduced in 4.1.0 (8ab74741).
Proposed fix
- Match only the real
src/srcset/sizesattributes (attribute name preceded by whitespace) and replace a single occurrence. - When the real
srcset(orsrc) is adata:placeholder, another script owns loading the image: leave the tag unchanged instead of adding eager candidates. - PHPUnit cases for an Envira-style tag.
- Ngôn ngữ chính
- PHP
- Star
- 74
- Fork
- 14
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Codeinwp/optimole-wp
-
bug bug-report bug-report-triage crash-report
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Codeinwp/optimole-wp#1187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug bug-report
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 56/100
Codeinwp/optimole-wp#1186 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
customer report feature-request-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Codeinwp/optimole-wp#1179 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add setting to disable Optimole URL rewriting for social meta tags (og:image / twitter:image)Đang mởcustomer report feature-request-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
Codeinwp/optimole-wp#1178 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug bug-report bug-report-triage crash-report regression
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Codeinwp/optimole-wp#1163 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Codeinwp/optimole-wp
Issue tương tự
-
sync-en
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
verbb/formie#3022 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Automattic/blocks-engine#3090 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(php): ORT workflow always fails due to incompatibility between Pluggy 1.7.0 and Scancode-Toolkit 32.5.0Có thể đã có người làm @leslie-bq đã nhận 3 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
valkey-io/valkey-glide-php#375 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100