Repository navigation
fix(image): SahajCloud URLs never match the Cloudflare variant pattern - #147
Conversation
… skipping it `BARE_CLOUDFLARE_URL_PATTERN` matched only `…/<account>/<image_id>/`, a shape no production read returns. `getCloudflareImagesUrl` defaults its variant to `public` (sydevs/SahajCloud `src/plugins/storage/cloudflareImagesAdapter.ts`), so every URL arrived as `…/<image_id>/public` and failed the test: `getImageURL` returned its input and `getImageSrcSet` returned `''`. The whole responsive pipeline — `SIZE_WIDTH_MAP`, `getVariantName`, `srcset`, `sizes`, and `buildLightboxSlide`'s largest variant — was inert, and one fixed `public` render was served to every device. `CLOUDFLARE_URL_PATTERN` now captures the base and treats the segment after it as a variant to **replace**, because `…/<image_id>/public/<variant>` does not resolve. The segment is matched loosely, so a flexible variant carrying `=` and `,` swaps out too. A deeper path still falls through untransformed, and so does the `/api/<collection>/file/<filename>` dev fallback. This repairs `<Image>`, `buildLightboxSlide`, `Splash`, `SplashLoader`, and the `og:image` in `lib/head.tsx` at once, since all five resolve through `getImageURL`. Four doc comments stated the bare-URL contract as fact. `getVariantName`'s claimed its result "exists in the Cloudflare dashboard"; nothing verifies that, and the dashboard entries are still unconfirmed. The fixtures were the reason the suite stayed green over dead code: both were bare URLs. The `/public` and flexible shapes are now covered, in the lib and at every call site, and all eight new cases were watched failing against the old pattern first. Refs #141 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015xLh9zhKbKXmsYKc5RYnzs
…puted srcset Review findings from the branch pass. `isCloudflareImageURL` kept its own `startsWith` notion of a Cloudflare URL while `CLOUDFLARE_URL_PATTERN` held the real one. The two disagreed for `…/<id>/<variant>/<extra>`: the predicate said yes, the pattern said no, so `<Image>` took the Cloudflare branch and rendered an untransformed `src` with no `srcset`, believing a variant had resolved. The predicate now reads the pattern, so there is one definition and they cannot drift. `getImageSrcSet` rebuilt and re-sorted its width list per call. That block was unreachable in production until the previous commit, which puts it on the SSR path of every image. The `<variant> <width>w` suffixes are now built once at module load, as `ASPECT_RATIO_ENTRIES` already is, leaving one regex and one join per call. Comments: the module header and the pattern note were roughly twice the length their content justified, and the pattern's claim that a deeper path "is not a shape Cloudflare serves" was wrong — Cloudflare allows `/` in a custom id. It is SahajCloud that cannot produce one, because `generateCloudflareImageId` slugifies every id with `strict: true`. The comment now states that, which is what makes the two-segment anchor safe. Tests: the four-entry video srcset was asserted verbatim three times, now one `it.each` over the bare, `/public` and flexible inputs. Two names still said "appends". A new case pins the shape the predicate now rejects. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015xLh9zhKbKXmsYKc5RYnzs
`AGENTS.md` and `DESIGN_SYSTEM.md` both described `<Image>` as appending a variant to a bare URL, and both asserted the returned name "always exists in the Cloudflare dashboard". Neither is true: SahajCloud sends `/public`, and nothing checks the dashboard. `docs/rules/testing.md` is the worse one. Its canonical `<Image>` example used the bare `…/<id>/` fixture, so a test copied from it reproduces exactly the blind spot that kept #141 green over dead code. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015xLh9zhKbKXmsYKc5RYnzs
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | b0a5905 | Commit Preview URL Branch Preview URL |
Oct 13 2026, 01:47 PM |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The central fix is right, and I verified the pattern and the producer side myself.
The diff is larger than #141's Phase 2, and the extra part is a srcset precompute against an uncounted cost. This PR also cannot be merged on its own evidence — #141's first criterion is a dashboard check — yet a clean review marks the draft ready.
Findings
- should-fix — unasked-for precompute, and a second definition of the variant name (
lib/cloudflare-images.ts:45) - should-fix —
isCloudflareImageURLno longer tests what it names (:51) - consider — the named-variant route keeps a dependency nothing can check (
:25)
Checked
lib/cloudflare-images.ts in full; its five call sites (Image.tsx:132,209, Splash.tsx:81, SplashLoader.tsx:130, head.tsx:51); the diff's tests; #141's criteria; the producer in SahajCloud (urlFields.ts:95,148,224); the pattern on seven shapes. Nothing reads previewUrl, so no flexible-variant URL reaches getImageURL. CI green on d28b5a3.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The precompute spelled `${aspectRatio}-${width}` itself, a second definition of
the variant name beside `getVariantName`. That made the flexible-variant route
cost two edits rather than one, which is the opposite of what this PR claims.
Iterating the size/width entries instead of the widths alone lets each suffix
come from `getVariantName(aspectRatio, size)`, so the name has one definition
again and the per-call saving is kept.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CFURvR2HQbpyj7e2GPzpoR
`isCloudflareImageURL` claimed to answer "is this a Cloudflare image URL", but once it read `CLOUDFLARE_URL_PATTERN` it answered "can this module resolve a variant on it" instead — so `…/<id>/public/extra` is a Cloudflare image URL and got `false`. A test existed only to pin that gap. The predicate was also redundant at all five call sites. `getImageURL` already returns its input when the pattern does not match, and `getImageSrcSet` already returns `''`, so every `isCloudflareImageURL(x) ? resolve(x) : x` was spelling out a fall-through the callee performs. Keeping it as a cheap prefilter stopped being true when it became the same regex: `<Image>` ran that regex three times per render, now twice. The `…/<id>/public/extra` and non-Cloudflare shapes stay covered where the behaviour lives, on `getImageURL` and `getImageSrcSet`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CFURvR2HQbpyj7e2GPzpoR
Deploying wemeditate-design with
|
| Latest commit: |
b0a5905
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3a8a4899.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-141-cloudflare-va.wm-design.pages.dev |
|
Addressed the adversarial review on 1dcd08b. Lean gate green: lint, Adopted
Asked, left open
Nothing rebutted. Phase 1 still gates the merge. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…lare-variant-replace # Conflicts: # AGENTS.md
|
Merged Lean gate green on the merge — 0 lint errors, types clean, 833 tests passed. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…nated names
Every name getVariantName produced (`video-800`, `4-3-1024`, …) is a
`400 malformed URL` on imagedelivery.net, so once the pattern accepted
`/public`, every SahajCloud image broke with no fallback. Probed live:
`square-400` 400, `square400` 403, `width=400` 200.
Flexible variants are already enabled on the account, so getVariantName
now returns `width=<n>` and no width needs a dashboard entry. Width only:
no server-side crop, so `forceAspectRatio={false}` still renders the
image's own ratio, and Cloudflare never upscales past the original.
Drops the dashboard TODO and the AGENTS.md rule that went with it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
…/<image_id>/public, which the old pattern rejected, so the whole responsive-image pipeline was inert.<Image>, the lightbox,Splash,SplashLoaderandog:imageat once./publicshape is now covered, in the lib and at every call site.width=<n>). The named{aspectRatio}-{width}form was a400 malformed URLfor every image, and flexible variants are already enabled on the account, so no dashboard step gates the merge.Changes
lib/cloudflare-images.ts—CLOUDFLARE_URL_PATTERNcaptures the base and treats the segment after it as a variant to replace.getVariantNamereturns a flexiblewidth=<n>variant and is the only place that spells it, including the srcset suffixes precomputed at module load. The dashboard TODO is gone.isCloudflareImageURLis gone.components/atoms/Image/Image.tsx,components/organisms/Splash/Splash.tsx,components/atoms/SplashLoader/SplashLoader.tsx,lib/head.tsx— the fiveisCloudflareImageURL(x) ? resolve(x) : xguards dropped. Plus doc comments that stated the bare-URL contract as fact.docs/rules/testing.md,AGENTS.md,DESIGN_SYSTEM.md— same, plus the canonical test example that taught the bad fixture.AGENTS.mdloses its "create each variant in the dashboard" rule.Preview
width=<n>srcsets, and every variant URL sampled returns200.Test results
lint+tsc --noEmit+test:run— 838 passed, 0 lint errors, on b0a5905getVariantNameManual verification
video-1024andsquare-400return400 malformed URL(Cloudflare rejects a hyphen in a variant segment),square400returns 403, andwidth=400/640/800/1024/1200/1536/2048— every widthSIZE_WIDTH_MAPholds — return200AVIF.curl -sIone generated variant URL per aspect ratio: expect200and animage/*content type.curl -s <preview-url>/<content-page> | grep -o 'srcset="[^"]*"' | head— returns nothing onmaintoday, should return srcsets here.Notes for reviewer
The route question is settled: flexible variants. #141 and the review on
lib/cloudflare-images.ts:25asked which Phase 1 route to take. Named variants turned out not to be an option as written, sogetVariantNamemoved towidth=<n>(b0a5905), with a spec that fails on any hyphenated name. Width only, no server-side crop, soforceAspectRatio={false}keeps the image's own ratio. This also settles #161 Q2 as A: flexible variants cannot serve an image that requires a signed URL.Filed on the way: #146. Four render paths reach an
imagedelivery.netURL with noAspectRatioand so still serve the/publicoriginal —Avatar,MeditationPlayer's frame image, theVideoPlayerposter, andContentCard/Column. Invisible before this fix, since everything served the original. Not fixed here; none of it is in this ticket's criteria.One review finding declined. A
resolveVariantURL(url, aspectRatio, size)helper would collapse thegetImageURL(url, getVariantName(…))pairing repeated at five sites. Worth doing, but it is a refactor of its own.Detail
Why the fixtures mattered more than the pattern. Both test fixtures were bare URLs —
…/<id>/and…/<id>— a shape no production read returns. So every assertion passed whilegetImageURLreturned its input andgetImageSrcSetreturned''for every real image.lib/related-content.ts:12already documented the real shape, so two files in the repo disagreed about it. The bare shape stays covered: the contract has to survive SahajCloud ever emitting one, which is #141's last criterion.The producer, verified rather than assumed.
getCloudflareImagesUrl(filename)defaultsvariantto'public'and returns`${deliveryUrl}/${filename}/${variant}`(sydevs/SahajCloudsrc/plugins/storage/cloudflareImagesAdapter.ts:29-36). Bothimagescall sites pass no variant (src/plugins/storage/urlFields.ts:95,:224). The only other shape a read returns is the dev fallback/api/<collection>/file/<filename>, which is not animagedelivery.netURL and passes through untouched.Why the base is anchored to two segments. Cloudflare permits
/inside a custom image id, which would make a three-segment path legitimate. SahajCloud cannot produce one:generateCloudflareImageIdrunsslugify(baseName, { strict: true }), and the preview prefix ispreview-(src/plugins/storage/filenameUtils.ts,src/plugins/storage/previewIsolation.ts:58). The comment on the pattern states this, because it is what makes the anchor safe. A deeper path falls through untransformed rather than being mangled.One latent bug found by the review, and then the predicate that carried it.
isCloudflareImageURLwas a barestartsWithwhileCLOUDFLARE_URL_PATTERNheld the real test. The two disagreed for…/<id>/<variant>/<extra>: the predicate said yes, the pattern said no, so<Image>took the Cloudflare branch and emitted an untransformedsrcwith nosrcset, believing a variant had resolved. Pointing the predicate at the pattern fixed the drift but left the name lying —…/<id>/public/extrais a Cloudflare image URL, and the predicate returnedfalse. The review's second finding took the better answer: the predicate is gone. Every call site readisCloudflareImageURL(x) ? resolve(x) : x, which is the fall-throughgetImageURLandgetImageSrcSetalready perform, so five guards went with it and<Image>runs the regex twice per render instead of three times. The…/<id>/public/extraand non-Cloudflare cases are now asserted where the behaviour lives.One performance note.
getImageSrcSetrebuilt and re-sorted its width list per call, and calledgetImageURLper width, re-running the regex each time. That block was unreachable in production until this PR, which puts it on the SSR path of every image. The<variant> <width>wsuffixes are built once at module load now — the same treatmentASPECT_RATIO_ENTRIESalready had — leaving one regex and one join per call. Each suffix is built throughgetVariantName, so the precompute is not a second definition of the variant name.Possible trivial merge with #144. That PR (for #142) replaces
Splash's backgrounddivwith animg. The newSplash.test.tsxhere asserts on the resolved URL rather than onstyle=, so it passes either way, but whichever merges second may need a one-line merge in that file.Not verifiable from a routine, as #141 warned: the SahajCloud API key in the cloud environment returns 403 on every endpoint, so no live-data check was possible, and there is no Cloudflare dashboard access at all. The producer-side claims above were verified by reading the SahajCloud checkout, not by calling the API.
Closes #141
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01CFURvR2HQbpyj7e2GPzpoR