Repository navigation
Description
Summary
The event detail view throws (hits the ErrorBoundary) for any event that has
images. Root cause: getEvent populates the image relation with { url, thumbnailURL, alt }
but not filename — and SahajCloud's image url is a virtual field derived
from filename, so it comes back null, which fails the url: z.string() parse.
A secondary bug: the resolved dev URL is relative (/api/images/file/…) and is
consumed raw, so even after the crash is fixed images 404 unless prefixed with the
SahajCloud origin.
Supersedes the earlier diagnosis in this issue (relax the schema). Relaxing
EventImageSchema.urlwould only swap the crash for silently-missing images —
it doesn't address whyurlis null. Confirmed against the SahajCloud source +
the running local backend (see Evidence).
Observed behavior
- Open an event that has ≥1 image, e.g.
http://localhost:5173/russia/voronezh/13. getEvent(fetch.ts:288-320) fetches/events/:id
(depth 1) withpopulate: { images: { url: true, thumbnailURL: true, alt: true } }
(fetch.ts:313) and runsEventDocSchema.parse(response.data)
(fetch.ts:318).- The image's
urlisnull, soEventImageSchema(event.ts:44,url: z.string())
fails →ZodError.useSuspenseQueryin EventView.tsx
re-throws it on render → error page.
Only events with images fail: images uses .default([]) (event.ts:112),
so an empty/absent array never runs per-image validation.
Root cause
On SahajCloud the images collection's url is a virtual: true field whose
afterRead hook builds the URL from data.filename and returns undefined when
filename is absent (SahajCloud/src/plugins/storage/urlFields.ts:116 virtualUrlField;
falsy-filename guard at :118). Our populate omits filename, so the hook has
nothing to build from and url resolves to null. Two further facts from the
backend:
thumbnailURLandsizesdo not exist on this collection —imageSizes
were removed in favour of Cloudflare Images flexible variants
(SahajCloud/src/collections/Images/Images.ts). Requesting them is dead weight
(always null).- URL shape is environment-dependent: absolute in prod
(https://imagedelivery.net/<hash>/<filename>/public) and relative in dev
(/api/images/file/<filename>,urlFields.ts:15getLocalFallbackUrl). So any
prefixing must be conditional — only relative URLs need the origin.
Evidence (running local backend, event 13)
# populate url + filename → url resolves
{"id":2,"filename":"picture-9-39a496daa3-3.jpg","url":"/api/images/file/picture-9-39a496daa3-3.jpg"}
# populate url only (today's behavior) → url null
{"id":2,"url":null}
# the file serves fine at the backend origin (relative URL just needs the origin)
GET http://localhost:3000/api/images/file/picture-9-39a496daa3-3.jpg → 200 image/jpeg 764KB
Expected behavior
An event with images renders its detail view without crashing, and its images
actually display (carousel + lightbox) with URLs pointing at the SahajCloud
origin / CDN.
Proposed changes
- Select
filenameso the virtualurlresolves. IngetEvent
(fetch.ts:313) change the images populate to
{ url: true, filename: true, alt: true }— and dropthumbnailURL(doesn't
exist). This alone fixes the crash:urlbecomes a valid string. - Origin-prefix relative image URLs so they render. Image URLs are consumed
raw as<img src>in the carousel slides
(EventDetails.tsx:106-114)
and the OG/JSON-LD image (EventMetadata.tsx:22).
Add a small helper (e.g. insrc/lib/shape/) that resolves an image URL against
the SahajCloud origin —new URL(url, import.meta.env.VITE_SAHAJCLOUD_URL).href
leaves absolute prod URLs untouched and prefixes relative dev URLs. Note the
clientbaseURLis${VITE_SAHAJCLOUD_URL}/api(client.ts:44),
and the URL already contains/api/…, so prefix with the origin
(VITE_SAHAJCLOUD_URL), not the axios baseURL, to avoid a doubled/api. - Optional hardening (not the fix): drop the non-existent
thumbnailURL
fromEventImageSchema(event.ts:43-48); and,
defensively, tolerate/skip an image whoseurlis still null (mirroring the
firstDate_tz/SafeUrlSchema.catch(null)patterns already in that file) so
a future null can't crash the whole event read.
Acceptance criteria
- Visiting an event that has images (e.g.
/russia/voronezh/13) renders the
detail view without throwing / hitting theErrorBoundary. - The event's images actually display in the carousel + lightbox (URL resolves
to the SahajCloud origin in dev / the CDN URL in prod — no 404 against the
widget's own origin). -
getEventselectsfilenameand no longer requests the non-existent
thumbnailURL. - The URL helper leaves already-absolute (
https://imagedelivery.net/…) URLs
unchanged and prefixes relative (/api/images/file/…) ones. - Unit test (node-only vitest) for the URL helper (absolute passthrough +
relative prefixing) and forEventDocSchemaparsing the real image shape
(filename+ relativeurl). - Lint + typecheck +
test:run+ build pass.
Files affected
src/config/api/fetch.ts—getEventimages populate (addfilename, dropthumbnailURL)src/lib/shape/— new image-URL resolver helper (origin-prefix)src/components/organisms/EventDetails/EventDetails.tsx— apply helper to slidesrcsrc/components/molecules/EventMetadata/EventMetadata.tsx— apply helper to OG/JSON-LD imagesrc/types/event.ts—EventImageSchema(dropthumbnailURL; optional defensiveurl)- co-located tests for the helper + schema
References
- SahajCloud source of truth:
src/plugins/storage/urlFields.ts:116(virtualUrlField, url built fromfilename),:15(getLocalFallbackUrl)src/plugins/storage/cloudflareImagesAdapter.ts:30(getCloudflareImagesUrl→imagedelivery.net/<hash>/<filename>/public)src/collections/Images/Images.ts(noimageSizes/thumbnailURL),src/collections/Events/Events.ts:176(imagesupload, hasMany)- client
select-required gate:src/plugins/usage/hooks.ts:117
- Confirmed live: event 13 image
urlisnullwithoutfilename,/api/images/file/…with it (serves 200).
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
[-]fix(event): tolerate null image URL so image events don't crash[/-][+]fix(event): resolve event image URLs (populate filename + prefix origin)[/+]