Skip to content

perf/lcp-hints: lcp-preload counts small logos/avatars as likely-LCP although the hero image is preloaded #516

Closed

Description

@deniskern

Summary

perf/lcp-hints → check lcp-preload warns "N likely-LCP images loaded without preload" on pages whose actual LCP image is preloaded (<link rel="preload" as="image" fetchpriority="high">). The extra "likely-LCP" candidates are small above-fold images: SVG logos with loading="eager" and 80×80 avatars. On a real site this produced one warning per page on 88 pages, while Lighthouse's lcp-discovery-insight passes all checks there.

Minimal repro

index.html (images are 1×1 PNG / empty SVG placeholders; only the declared sizes matter):

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>LCP preload repro page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preload" as="image" href="/hero.png" fetchpriority="high">
</head><body>
<header>``&lt;img src="/logo1.svg" alt="Logo one" width="120" height="40" loading="eager"&gt;&lt;img src="/logo2.svg" alt="Logo two" width="120" height="40" loading="eager"&gt;``</header>
<main><h1>Repro</h1>
``&lt;img src="/hero.png" alt="Hero" width="1200" height="800" fetchpriority="high"&gt;``
``&lt;img src="/avatar1.png" alt="Avatar one" width="80" height="80"&gt;&lt;img src="/avatar2.png" alt="Avatar two" width="80" height="80"&gt;``
</main></body></html>
python3 -m http.server 8765 --bind 127.0.0.1
squirrel audit http://127.0.0.1:8765/ --http -f json

Actual

{"name":"lcp-preload","status":"warn","message":"2 likely-LCP images loaded without preload","affectedPages":["http://127.0.0.1:8765/"]}

Expected

No lcp-preload warning: the page's largest above-fold image (1200×800 hero) is preloaded with fetchpriority="high". Only one element can be the LCP; once a preloaded candidate clearly dominates by declared size, smaller images (SVG logos, ≤ ~100×100 avatars/icons) should not count as additional likely-LCP candidates.

Versions

squirrel 0.0.105 (macOS arm64).

Acceptance Criteria

  • The issue's repro page produces an lcp-preload pass from perf/lcp-hints
  • SVG images, images inside header or nav, and images whose declared width and height are both under 300px are not counted as likely-LCP, the same eligibility perf/lcp-fetchpriority uses
  • Images with no declared dimensions remain eligible
  • A preload that differs from the image only by relative versus absolute URL, query string, or that matches through imagesrcset, counts as preloading that image
  • perf/lcp-hints and perf/lcp-fetchpriority pick the same hero candidate on the same page, from one shared helper
  • The count is not capped at 1 in this issue (kept as a possible follow-up)
  • The unused validateCWVHints function is removed if nothing calls it
  • docs/rules/perf/lcp-hints.mdx describes the new candidate rules
  • Test: apps/cli/tests/rules/lcp-hints.test.ts, the reporter's repro (two logos, then a preloaded hero): passes
  • Test: same file, the same page without the hero preload: warns with value 1
  • Test: same file, the existing undimensioned two-image case still warns with value 2
  • Test: same file, an absolute-URL preload for a relative src: passes
  • Test: same file, a preload with a query string and a preload through imagesrcset: pass
  • Test: same file, a small avatar image (under 300px declared) before the hero: not counted
  • Test: same file, an SVG logo before the hero: not counted
  • The PR description states whether the squirrelscan agent skill needs a change (the skill links to the rule pages, which are the reference, so usually none); if it does, a follow-up is filed against squirrelscan/skills

Generated by Claude Code

Activity

  1. self-assigned this
    on Oct 7, 2026
  2. added
    bug
    P3
    size: S
    rules
    P2
    and removed
    P3
    on Oct 7, 2026
  3. nc9 commented on Oct 7, 2026

    @nc9
    Contributor

    Triage notes (maintainer review):

    • Confirmed on current main, but the diagnosis in the report is partly off. The rule takes the first three non-lazy images in document order and has no size check at all. In the repro those three are the two logos and the hero; the hero matches its preload, so the two logos produce the "2". The avatars are never reached.
    • perf/lcp-fetchpriority already has a better candidate finder (skips SVG, header and nav images and anything declared under 300px, normalises URLs, reads srcset), so the two LCP rules disagree today. A third copy of the "first three" logic lives in lazy-above-fold. The fix moves the better finder to a shared helper.
    • The original criteria referred to a perf/cwv rule; that function has no callers, so it is dead code and can be removed.
    • Priority raised to P2 (a weight 7 warning on nearly every site with an eager header logo). Acceptance criteria rewritten with the unit tests split out.
  4. added a commit that references this issue on Oct 8, 2026
    1ee0552
  5. nc9 commented on Oct 8, 2026

    @nc9
    Contributor

    Acceptance check against main 1222727:

    # Criterion Result Evidence
    1 The issue's repro page produces an lcp-preload pass PASS packages/rules/src/performance/cwv.ts:326-328, apps/cli/tests/rules/lcp-hints.test.ts "reporter repro (two logos, preloaded hero) passes"
    2 SVG, header/nav and small declared images are not counted PASS packages/rules/src/shared/lcp-candidate.ts:16-22 and :58-64, lcp-hints.test.ts "an SVG logo before the hero is not counted", "a small avatar before the hero is not counted", "an image in header or nav is not counted"
    3 Images with no declared dimensions remain eligible PASS packages/rules/src/shared/lcp-candidate.ts:19-20, lcp-hints.test.ts "undimensioned two-image case still warns with value 2"
    4 Relative vs absolute, query string, imagesrcset preloads count PASS packages/rules/src/shared/lcp-candidate.ts:29-36, :76-99, lcp-hints.test.ts "an absolute-URL preload for a relative src passes", "a preload with a query string passes", "a preload through imagesrcset passes"; negative control "a preload for another image does not clear the hero"
    5 Both rules pick the same hero from one shared helper PASS packages/rules/src/performance/cwv.ts:10-13,327 and packages/rules/src/performance/lcp-fetchpriority.ts:6-9,35 import packages/rules/src/shared/lcp-candidate.ts; lcp-hints.test.ts "the unpreloaded hero lcp-hints counts is the one lcp-fetchpriority flags"
    6 The count is not capped at 1 PASS packages/rules/src/performance/cwv.ts:22 (MAX_LCP_CANDIDATES = 3), lcp-hints.test.ts "undimensioned two-image case still warns with value 2"
    7 validateCWVHints removed PASS no occurrence of validateCWVHints on main
    8 docs/rules/perf/lcp-hints.mdx describes the new candidate rules PASS docs/rules/perf/lcp-hints.mdx:19-26
    9 Test: reporter's repro passes PASS lcp-hints.test.ts "reporter repro (two logos, preloaded hero) passes"
    10 Test: without the hero preload warns with value 1 PASS lcp-hints.test.ts "the same page without the hero preload warns with value 1"
    11 Test: undimensioned two-image case warns with value 2 PASS lcp-hints.test.ts "undimensioned two-image case still warns with value 2"
    12 Test: absolute-URL preload for a relative src passes PASS lcp-hints.test.ts "an absolute-URL preload for a relative src passes"
    13 Test: query string and imagesrcset preloads pass PASS lcp-hints.test.ts "a preload with a query string passes", "a preload through imagesrcset passes"
    14 Test: small avatar before the hero not counted PASS lcp-hints.test.ts "a small avatar before the hero is not counted" (value 1)
    15 Test: SVG logo before the hero not counted PASS lcp-hints.test.ts "an SVG logo before the hero is not counted" (value 1)
    16 PR states whether the agent skill needs a change PASS PR 558 description: the agent skill needs no change

    Ran on a clean main checkout: apps/cli tests/rules/lcp-hints.test.ts; packages/rules tests/cwv-reuse.test.ts, tests/lcp-fetchpriority.test.ts, tests/noscript-content.test.ts, all green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugrulessize: S

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions