Skip to content

Fix image dedup collapsing distinct images that share generic alt text (#286)#305

Open
Imccccc wants to merge 1 commit into
kepano:mainfrom
Imccccc:fix/image-dedup-generic-alt
Open

Fix image dedup collapsing distinct images that share generic alt text (#286)#305
Imccccc wants to merge 1 commit into
kepano:mainfrom
Imccccc:fix/image-dedup-generic-alt

Conversation

@Imccccc

@Imccccc Imccccc commented Jun 8, 2026

Copy link
Copy Markdown

Problem

_deduplicateImages keyed its out-of-figure pass on alt text: a run of images sharing the same non-empty alt but differing in src was treated as lazy-load / reader-mode duplicates and collapsed to a single image.

That assumption holds for a large/small variant pair, but breaks whenever many distinct images share a generic identical alt:

On a real WeChat article this collapsed 28 distinct inline images down to 1 — the long-standing "Web Clipper only saves the first image from 公众号" symptom traces directly here.

Root cause

In the second loop of _deduplicateImages, the duplicate signal was same alt && different src. With N distinct images all carrying the same generic alt, each pair matched and all but one were removed.

Fix

Dedup the out-of-figure pass on image identity rather than alt:

  • Two images are duplicates only when their normalized src (host + path, ignoring the query string) matches but the raw src differs — i.e. a size/query variant of the same asset.
  • Distinct images (different normalized src) are never merged on alt alone.
  • The existing identical-src = legitimate repeat behavior is preserved (e.g. the same formula image used twice).

The in-figure pass and the lightbox pass are unchanged.

Testing

  • New tests/image-dedup-generic-alt.test.ts: distinct images sharing an identical generic alt / empty alt / WeChat-style mmbiz markup all survive; a legitimately repeated identical-src image still keeps both copies.
  • Full suite green (npm test): 312/312, including the existing elements--image-dedup, elements--lazy-image, elements--lightbox-image-dedup, and elements--svg-placeholder-lazy-image fixtures — no regressions.
  • Verified on the raw post-scroll HTML of a real WeChat article: 1 → 28 inline images. (Remaining drops are a 1×1 SVG tracking pixel and sub-130px decorative icons, correctly filtered.)

Fixes #286.

_deduplicateImages keyed its out-of-figure pass on alt text: a run of
images sharing the same non-empty alt but differing in src was treated as
lazy-load/reader-mode duplicates and collapsed to one. That assumption
breaks whenever many *distinct* images share a generic identical alt —
image galleries, and WeChat 公众号 (mp.weixin.qq.com) articles in
particular, where every inline image gets alt="Image". On a real WeChat
article this collapsed 28 inline images down to 1.

Dedup the out-of-figure pass on image identity instead: two images are
duplicates only when their normalized src (host + path, ignoring the query
string) matches but the raw src differs (a size/query variant of the same
asset). Distinct images are never merged on alt alone, and the existing
"identical src = legitimate repeat" behavior is preserved.

Fixes kepano#286.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Lazy-loaded article images with generic identical alt text are deduplicated away

1 participant