Skip to content

fix: hold back a lazy image's sources until it is visible - #21

Merged
lxsmnsyc merged 2 commits into
solidjs:mainfrom
brenelz:fix/lazy-source-fetch
Nov 27, 2026
Merged

lxsmnsyc merged 2 commits into
solidjs:mainfrom
brenelz:fix/lazy-source-fetch

Conversation

@brenelz

@brenelz brenelz commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

A lazy SolidImage downloads one of its variants before it scrolls into view. The framework-compare SolidStart port test caught it: an image 2400px below the fold made one AVIF request before any scrolling.

The server rendered the <source srcset> tags inside <picture> for every image, and only swapped the lazy <img> for a blank SVG. The browser selects a picture's image from its <source> elements first, so it fetched the chosen variant as soon as the page was parsed, whatever the <img> pointed at.

The sources now render under the same visible() condition as the real <img>: when the image is eager or has entered the observer's root margin. On the server a lazy image is never visible, so the server and the first client render agree and hydration is unchanged. Eager images still render their sources on the server.

Three existing server tests that assert on <source> attributes now pass eager, since a lazy image no longer has sources in the server HTML.

Verification

  • pnpm test: 211 tests pass (node and Chromium browser projects).
  • New tests, both of which fail against main:
    • Server render: "renders no for a lazy image on the server".
    • Browser: "does not fetch the preferred variant before the image scrolls into view". It uses same-origin variant URLs and Resource Timing, because data URLs are not recorded there.
  • pnpm build and tsc --noEmit pass.

Not checked in a hydrated SolidStart app.

Left open

When the component renders only in the browser, with no server render, the <noscript> fallback <img> is a live element with a srcset. Chrome can then fetch the fallback-format variant early if the image is within its lazy-load distance. This change does not touch that.

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/image@21

commit: 61b7673

@lxsmnsyc
lxsmnsyc merged commit 3d3a8a2 into solidjs:main Nov 27, 2026
5 checks passed
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