Skip to content

fix(image): SahajCloud URLs never match the Cloudflare variant pattern - #147

Merged
sydevs-bot merged 8 commits into
mainfrom
claude/fix-141-cloudflare-variant-replace
Oct 13, 2026
Merged

sydevs-bot merged 8 commits into
mainfrom
claude/fix-141-cloudflare-variant-replace

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every SahajCloud image URL arrives as …/<image_id>/public, which the old pattern rejected, so the whole responsive-image pipeline was inert.
  • A variant now replaces that segment instead of being skipped, repairing <Image>, the lightbox, Splash, SplashLoader and og:image at once.
  • Fixtures were the reason the suite stayed green over dead code. The /public shape is now covered, in the lib and at every call site.
  • Variants are Cloudflare flexible variants (width=<n>). The named {aspectRatio}-{width} form was a 400 malformed URL for 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_PATTERN captures the base and treats the segment after it as a variant to replace. getVariantName returns a flexible width=<n> variant and is the only place that spells it, including the srcset suffixes precomputed at module load. The dashboard TODO is gone. isCloudflareImageURL is gone.
  • components/atoms/Image/Image.tsx, components/organisms/Splash/Splash.tsx, components/atoms/SplashLoader/SplashLoader.tsx, lib/head.tsx — the five isCloudflareImageURL(x) ? resolve(x) : x guards 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.md loses its "create each variant in the dashboard" rule.

Preview

Test results

  • Lean gate: ✓ lint + tsc --noEmit + test:run — 838 passed, 0 lint errors, on b0a5905
  • Targeted specs: 8 new cases, all watched failing against the old pattern before the fix, plus a no-hyphenated-variant spec watched failing against the old getVariantName
  • Build: N/A — no build, server or Wrangler config changed

Manual verification

  1. ✓ Flexible variants are on. Probed with a real image: video-1024 and square-400 return 400 malformed URL (Cloudflare rejects a hyphen in a variant segment), square400 returns 403, and width=400/640/800/1024/1200/1536/2048 — every width SIZE_WIDTH_MAP holds — return 200 AVIF.
  2. curl -sI one generated variant URL per aspect ratio: expect 200 and an image/* content type.
  3. curl -s <preview-url>/<content-page> | grep -o 'srcset="[^"]*"' | head — returns nothing on main today, should return srcsets here.

Notes for reviewer

The route question is settled: flexible variants. #141 and the review on lib/cloudflare-images.ts:25 asked which Phase 1 route to take. Named variants turned out not to be an option as written, so getVariantName moved to width=<n> (b0a5905), with a spec that fails on any hyphenated name. Width only, no server-side crop, so forceAspectRatio={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.net URL with no AspectRatio and so still serve the /public original — Avatar, MeditationPlayer's frame image, the VideoPlayer poster, and ContentCard/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 the getImageURL(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 while getImageURL returned its input and getImageSrcSet returned '' for every real image. lib/related-content.ts:12 already 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) defaults variant to 'public' and returns `${deliveryUrl}/${filename}/${variant}` (sydevs/SahajCloud src/plugins/storage/cloudflareImagesAdapter.ts:29-36). Both images call 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 an imagedelivery.net URL 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: generateCloudflareImageId runs slugify(baseName, { strict: true }), and the preview prefix is preview- (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. isCloudflareImageURL was a bare startsWith while CLOUDFLARE_URL_PATTERN held 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 untransformed src with no srcset, believing a variant had resolved. Pointing the predicate at the pattern fixed the drift but left the name lying — …/<id>/public/extra is a Cloudflare image URL, and the predicate returned false. The review's second finding took the better answer: the predicate is gone. Every call site read isCloudflareImageURL(x) ? resolve(x) : x, which is the fall-through getImageURL and getImageSrcSet already perform, so five guards went with it and <Image> runs the regex twice per render instead of three times. The …/<id>/public/extra and non-Cloudflare cases are now asserted where the behaviour lives.

One performance note. getImageSrcSet rebuilt and re-sorted its width list per call, and called getImageURL per 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>w suffixes are built once at module load now — the same treatment ASPECT_RATIO_ENTRIES already had — leaving one regex and one join per call. Each suffix is built through getVariantName, so the precompute is not a second definition of the variant name.

Possible trivial merge with #144. That PR (for #142) replaces Splash's background div with an img. The new Splash.test.tsx here asserts on the resolved URL rather than on style=, 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

claude added 3 commits October 1, 2026 17:09
… 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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 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 b0a5905 Commit Preview URL

Branch Preview URL
Oct 13 2026, 01:47 PM

@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
@sydevs-bot

sydevs-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 19:27Z resolve-conflicts · attempt 1 · session · done
  • 19:27Z resolve-conflicts · attempt 1 · session
  • 17:29Z address-review · attempt 1 · session · done
  • 17:29Z address-review · attempt 1 · session
  • 17:21Z adversarial-review · attempt 1 · session · done

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

@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

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 — isCloudflareImageURL no 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

Comment thread lib/cloudflare-images.ts Resolved
Comment thread lib/cloudflare-images.ts Resolved
Comment thread lib/cloudflare-images.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 1, 2026
@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
claude added 2 commits October 1, 2026 17:32
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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review on 1dcd08b. Lean gate green: lint, tsc --noEmit, 796 tests.

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 1, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 1, 2026 17:38
@sydevs-bot
sydevs-bot requested a review from Ardnived October 1, 2026 17:38
@sydevs-bot
sydevs-bot enabled auto-merge October 1, 2026 17:38
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Oct 11, 2026
…lare-variant-replace

# Conflicts:
#	AGENTS.md
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. One conflict, in AGENTS.md: this branch rewrote the Cloudflare Images bullet while main added the public/ bullet right after it. Kept both.

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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 11, 2026
…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]>
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit a681273 Oct 13, 2026
24 of 25 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-141-cloudflare-variant-replace branch October 13, 2026 13:50
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 13, 2026
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): SahajCloud URLs never match the Cloudflare variant pattern

3 participants