Skip to content

fix(image): the LCP hero is lazy-loaded and preload-invisible - #144

Merged
sydevs-bot merged 9 commits into
mainfrom
claude/fix-142-lcp-hero-eager-image
Oct 2, 2026
Merged

sydevs-bot merged 9 commits into
mainfrom
claude/fix-142-lcp-hero-eager-image

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The lead splash hero paints as an <img loading="eager" fetchPriority="high"> instead of an inline CSS background-image, so the preload scanner can see it.
  • React 19 hoists a <link rel="preload" as="image"> for that element, so the preload the repo lacked needs no hand-written <link>.
  • A splash that is not the page's first block stays loading="lazy", and no other image changes.

Preview

Preview pending — Cloudflare names it after a branch slug, so the alias only exists once the build posts. When it does, open:

  • The web preview, on any SahajCloud page that leads with a splash — run the Manual verification greps against it.
  • The Ladle preview, Organisms → Splash → "LCP Priority" — the new section's markup carries loading="eager", fetchPriority="high" and the hoisted preload link.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint (0 errors), tsc --noEmit, vitest run
  • Targeted specs: 792 passed, 78 files. 7 new: 5 in blockConverters.test.tsx, 2 in RichText.test.tsx
  • Build: N/A — no build, server or Wrangler change

The RichText.test.tsx specs render through the library's own converter dispatch rather than a hand-built argument object, so if @payloadcms/richtext-lexical ever stopped supplying childIndex/parent the hero would not silently revert to lazy.

Manual verification

Against the web preview, on a page that leads with a splash:

  1. curl -s <url> | grep -ioc 'fetchpriority="high"' — at least 1. Grep case-insensitively: React serialises the attribute as fetchPriority.
  2. curl -s <url> | grep -c 'rel="preload"' — at least 1.
  3. curl -s <url> | grep -c 'background-image' — 0.
  4. Lighthouse mobile: the LCP element is the hero image, and "Largest Contentful Paint image was lazily loaded" does not fire.

Notes for reviewer

The ticket's open question is still open, and criterion 4 answers it one way. A splash below the lead block is now loading="lazy". A CSS background was neither lazy nor eager, so either choice is a change. If a page ever puts a short paragraph above a full-screen splash, that hero is largely in the viewport and lazy would start its fetch later than today. Say the word and it becomes loading={undefined} for the second root block.

ultrawide-2048 is not what ships. Splash asks for it, but getImageURL returns its input for every URL SahajCloud actually serves (/public, per #141), so the hero gets one fixed variant before and after this PR. The <img> therefore carries no srcSet/sizes — that is #141's work, not this PR's, and this PR does not make it worse.

priority trusts getLeadSplash's assumption. PageTemplate still renders a featuredVideo/author byline above RichText, so a page with both a lead splash and a featured video would put chrome above the "hero". That assumption is already shipped — getLeadSplash drives LayoutChrome's overlaid header and flush-to-top spacing the same way — so making priority disagree with it would be worse. I could not confirm whether such a page exists: SahajCloud returns 403 to this session's key.

Adversarial review, and what it changed

Three findings, all answered on the thread.

Dismissed review findings, and why

Four of eleven findings across /simplify and /code-review high were dismissed.

  • "Route the hero through the Image atom and add priority there instead." Both of the ticket's blockers hold. Image.tsx:306 keeps the image at opacity-0 until hydration fires onLoad, which excludes it from LCP candidacy; and its container is relative ${aspectRatioStyles} ... while className reaches the image, not the container. The suggested <Image priority className="absolute inset-0 w-full h-full"> would absolutely position the <img> against that relative wrapper — a zero-height box in Splash's flex parent — so the hero would not fill the viewport. Making it work needs the atom's container layout changed too, which is the wider defect the ticket deferred. Avatar.tsx:113 is the existing precedent for a hand-rolled <img>. Filed separately as fix(image): the Image atom hides every image until hydration #145.
  • "Force loading off for the second root block too." Acceptance criterion 4 requires loading="lazy" for a non-lead splash. Surfaced above instead of overridden.
  • "Non-lead splashes have no fallback background, so dark-theme text can render white-on-white while the lazy image loads." Real, but pre-existing for the whole load window, and picking a fallback colour is a design call. Not taken unattended.
  • "alt="" and aria-hidden="true" are redundant on one <img>." True, and both are what the ticket prescribes; the <div> being replaced carried aria-hidden too. Kept.

Accepted: the three new comments were trimmed to the why each carries, the story's duplicate non-priority panel was dropped (five other sections already render a default splash) and then unclipped to match its neighbours, and the contract-level test was added.

Why an element and not a hand-written <link>

Verified against the installed [email protected] rather than assumed. react-dom-server's case "img" emits a hoisted <link rel="preload" as="image"> for any <img> with a src unless it is loading="lazy", fetchPriority="low", a data: URI, or inside <picture>/<noscript>. It can also route that preload into a Link: response header instead of the HTML, but only when onHeaders is configured — nothing in this repo or in vike/vike-react sets it, so the <link> lands in the document. renderToStaticMarkup reproduces it, which is what makes criterion 3 assertable in CI rather than only by curl.

Fixture pre-mortem: the specs assume an upload ref is a populated object with a non-empty string url, which is all populatedImage (lib/content-blocks.ts:213) and isPopulated (lib/payload-relationships.ts:9) require — both read directly. They also assume root-level children arrive with childIndex: i and parent: data.root; that is the real dispatch in @payloadcms/richtext-lexical's convertLexicalNodesToJSX, and JSXConverterArgs declares both, so the RichText.test.tsx specs exercise it rather than trusting it.

Closes #142

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5

claude and others added 5 commits September 30, 2026 19:21
A CSS `background-image` is invisible to the browser's preload scanner
and cannot carry `fetchPriority`, so the hero request only starts once
the render tree is built. An `img` element can, and React emits a
hoisted `<link rel="preload" as="image">` for a non-lazy one, so the
preload this repo lacks comes for free.

`priority` defaults to false, so every splash is lazy until its caller
opts in. The next commit gives the lead splash that opt-in.

Co-authored-by: sydevs-bot <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5
Only the page's first root-level block is above the fold, so only it
should preempt the network. `getLeadSplash` decides the same thing from
`page.content`, but nothing threads its answer into a converter, so the
position comes from the converter args: root-level children are
dispatched with `childIndex: i` and `parent: data.root`.

A splash anywhere else keeps `loading="lazy"`, which a CSS background
never had either way.

Co-authored-by: sydevs-bot <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5
Trim the three new comments to the why each carries, and drop the story's
duplicate non-priority panel — five other sections already render a
default splash, and the two differed only in markup.

Co-authored-by: sydevs-bot <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5
…ispatch

The blockConverters specs hand-build `childIndex` and `parent`, so a
library change that stopped supplying either would revert the hero to
lazy with the suite still green. This renders RichText instead, which
drives the library's own dispatch.

Also unclip the new story section, which was the only clipped
full-bleed splash in the file.

Co-authored-by: sydevs-bot <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5
The `Image` atom's `opacity-0`-until-hydration gate silently disqualifies
any hero routed through it, so the next contributor to "simplify" a
hand-rolled hero img back into the atom would regress LCP with no test
failing.

Co-authored-by: sydevs-bot <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kc1j19vPbg9MtAwdbWJ2P5
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web f1c0875 Commit Preview URL

Branch Preview URL
Oct 01 2026, 09:05 PM

@sydevs-bot

sydevs-bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 3

recent dispatches
  • 21:13Z fix-ci · attempt 1 · session · done
  • 21:13Z fix-ci · attempt 1 · session
  • 21:09Z fix-ci · attempt 1 · session · done
  • 21:09Z fix-ci · attempt 1 · session
  • 21:05Z fix-ci · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 30, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

Proportionate to #142: ~25 source lines, the rest tests and a story. Earning React's hoisted preload beats a hand-written <link>. Splash has one consumer, so no other hero silently drops to loading="lazy". Two things reach past the ticket, neither blocking: a doc rule #145 already claims, and a second definition of "the lead block".

Findings

  • should-fix — DESIGN_SYSTEM.md:284 states a permanent rule that #145 contradicts and that fights line 283.
  • consider — blockConverters.tsx:311 restates getLeadSplash's predicate in a second file.
  • consider — Splash.stories.tsx:98 adds a panel identical to its five neighbours.

What was checked

Read whole: Splash.tsx, the splash converter, its story, content-blocks.ts:260-310, RichText.tsx:243-275 — withDebugOverlay forwards args whole, so debug keeps childIndex. Grepped every <Splash and getLeadSplash site: one and four. No contract surface touched. React's <picture> rule comes from #145: no node_modules here to re-check it.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread DESIGN_SYSTEM.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 30, 2026
The bullet stated "never the <Image> atom" as a permanent rule. #145 makes
<Image priority> the right answer above the fold, and the WebP bullet above
it recommends <picture>, which suppresses the hoisted preload. A contributor
reading both got no answer. Keep the durable half — eager plus high
fetchPriority, no CSS background — and scope the atom's exclusion to today.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TEabkgbbusRKFZzDmddi4D
Every other StorySection in this file passes inContext, so the new panel
rendered without the divider its neighbours get.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TEabkgbbusRKFZzDmddi4D
The converter reads childIndex/parent, getLeadSplash reads
content.root.children[0]. They agree today and nothing kept them agreeing,
so drift would point the overlaid header at a lazy image while the preload
stayed on the old block. Assert both answers on the same content tree.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TEabkgbbusRKFZzDmddi4D
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: f1c0875
Status: ✅  Deploy successful!
Preview URL: https://461e025e.wm-design.pages.dev
Branch Preview URL: https://claude-fix-142-lcp-hero-eage.wm-design.pages.dev

View logs

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review. Pushed 719064e. Lean gate green — lint 0 errors, tsc --noEmit, 792 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 30, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 30, 2026 21:31
@sydevs-bot
sydevs-bot requested a review from Ardnived September 30, 2026 21:31
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 1, 2026
One conflict, in the DESIGN_SYSTEM.md Performance list. Both sides added an
above-the-fold image rule to the same bullet position.

main (#148) fixed the Image atom's opacity-0-until-hydration gate and gave it
a priority prop, so this branch's bullet cited a blocker that no longer
exists. The second blocker still holds: the atom's container owns the layout
and className reaches the image, and #145 deferred a fill mode, so a hero
that must fill its parent still hand-rolls an img. The resolved bullet keeps
that reason, main's `<Image priority sizes>` guidance and its one-or-two-per-
page cap, and the never-a-CSS-background and `<picture>`-suppresses-the-
preload rules. main's separate first-render-must-be-visible bullet is kept
whole.

Splash.tsx carried the same stale opacity-0 reason in a comment. git merged
it clean because main never touched the file, so it is corrected here to the
container-layout reason it now rests on.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DzGDzXPkGrSomd1FAi7Ern
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main (944b7c0) in and pushed f1c0875. One conflict, in the DESIGN_SYSTEM.md Performance list: both sides added an above-the-fold image rule at the same bullet.

The resolved bullet keeps both. From this branch: never a CSS background-image, and <picture> suppresses the hoisted preload. From main: <Image priority sizes>, and the one-or-two-images-per-page cap. main's separate first-render-must-be-visible bullet is kept whole.

One half of this branch's bullet was dropped, because main made it false. #148 removed the Image atom's opacity-0-until-hydration gate and gave it a priority prop, so that is no longer a reason to hand-roll an <img>. The second reason still holds — the atom's container owns the layout and className reaches the image, and #145 deferred a fill mode — so the bullet now rests on that, and Splash keeps its element.

Splash.tsx carried the same stale reason in a comment. main never touched the file, so git merged it clean; it is corrected in the same commit.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 1, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

No code change — CI is green on f1c0875.

GitHub created two CI runs for the same pull_request event: 214 and 215. cancel-in-progress cancelled 214 at 21:04:51. The dispatcher re-derived CI on unlock at 21:05:56, when 214's three check runs were terminal cancelled and 215 was still running — so it read them as failures.

Run 215 finished at 21:06:07. Smoke (web), Smoke (ladle) and Lint, Typecheck & Unit all passed on this sha.

cancelled counts as failing in merge-gate.mjs, and ci.ignoreCheckNames covers only the dispatcher's own checks, so a later gate pass reads 214's rows and calls this PR red again.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 1, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

CI is still red after 3 fix attempts (failing: Smoke (web), Smoke (ladle), Lint, Typecheck & Unit). I have stopped retrying. A comment or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 3b7469f Oct 2, 2026
44 of 48 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-142-lcp-hero-eager-image branch October 2, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(image): the LCP hero is lazy-loaded and preload-invisible

3 participants