Skip to content

feat(about): carousel photos in Payload, compressed on upload - #53

Merged
maxitect merged 6 commits into
mainfrom
feat/43-carousel-photos-in-payload-with-images-compressed
Nov 13, 2026
Merged

maxitect merged 6 commits into
mainfrom
feat/43-carousel-photos-in-payload-with-images-compressed

Conversation

@maxitect

@maxitect maxitect commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

The About page carousel now reads its photos from Payload, and every image uploaded to media is compressed, in the browser before it leaves the admin and again on the server as a safety net. With no photos in the global, the page keeps showing the repo images.

Changes

  • About page global: a carousel array of one photo upload (to media) and a localised, required alt. One migration, 20261113_001547_carousel: two child tables with real foreign keys, no _rels table.
  • media uploads: Payload's resizeOptions (2560 px, never enlarged), formatOptions (progressive JPEG, quality 80) and mimeTypes limited to JPEG, PNG and WebP, the formats both the browser and the server re-encode as a still JPEG.
  • Admin compression: a ui field on media (ImageCompressor) watches the form's file, re-encodes with jSquash (@jsquash/jpeg, @jsquash/resize) and swaps the file before submit. It shows the original and compressed size, and uploads the original when the codec cannot run. Payload has a slot that replaces the Upload section (admin.components.edit.Upload), but using it means re-implementing the stock Upload, whose props the slot does not receive; a ui field with useField({ path: "file" }) reaches the same form value without copying Payload's code.
  • CSP: 'wasm-unsafe-eval' in script-src for /admin only.
  • AboutClient takes the photos from the cached About reader (getAboutPage). carouselFallback.ts holds the four repo images and their alt texts, used while the global has no photos.
  • content:import imports the four photos (media rows and global) in order, and skips when the global already has photos.

Acceptance criteria

AC Result Method Evidence
After the import, the About page shows the same four photos, order and alt texts, EN and FR, 1280 and 390 PASS browser AC1 below
A fifth photo added in the admin shows without a redeploy; removing and reordering work too PASS api AC2 below
A photo cannot be saved without alt text in both languages PASS, see note api AC3 below
On the deploy preview a 12 MB phone JPEG and a large PNG upload without a 413 and the body is under 2 MB PASS deploy AC4 below
Stored as JPEG, at most 2560 px, under 1 MB PASS deploy, db AC5 below
A file uploaded through the API is still compressed PASS api AC6 below
A non-image is rejected PASS api, browser AC7 below
Keyboard navigation, live region and reduced motion still work PASS browser, code AC8 below

Closes

Closes #43

Notes

  • Deviation, alt text: Payload validates a localised required field for the locale being saved only, so "both languages" means a blank alt is rejected in English and in French. A new photo saved in English alone passes, and the French page shows the English alt through fallback: true. Payload has no supported way to require the other locale in the same save.
  • media.alt stays required and localised as it was, so an editor creating a photo inline fills it as well as the row's alt. The import fills both.
  • The migration generator also emitted an unrelated ALTER TABLE "calendar_settings" ... SET DEFAULT false (snapshot drift from Advent calendar live at /calendrier by 1 December #29; production's column already has that default). I removed it from up and down.
  • Deleting a media file that is in the carousel fails at the database (photo_id is NOT NULL, Payload makes the key ON DELETE SET NULL), which protects the page.
  • The Carousel component is untouched, to keep the rebase with Performance: home page weight, images, caching and function region #35 small. Its fixed 5000x500 Image dimensions are Performance: home page weight, images, caching and function region #35's.
  • Dev-only: after editing a client component, the Payload login page in next dev sometimes loops with "Maximum update depth exceeded" until the server restarts. It never appeared on a fresh server or in the production build.
  • Only JPEG, PNG and WebP are accepted. Sharp turns an animated GIF into one tall JPEG of every frame, and it cannot resize SVG or HEIC, so those are rejected with a 400 instead of being stored broken or uncompressed.
  • An animated WebP sent through the API (not the admin) is still stored as a tall strip of its frames; the admin path keeps its first frame. A transparent PNG becomes a JPEG on a white background in the admin and on black through the API.

After merge (for the user)

  1. The production build runs payload migrate on Neon main: 20261113_001547_carousel applies on top of initial, calendar and calendar_checks (proved below on preview reset from main).
  2. The band uploads its photos at /admin/globals/about-page, or run NODE_ENV=production pnpm content:import against main to import the four current photos. Until then the page shows the repo images.
  3. Once production shows the Payload photos, delete public/images/carousel/ and src/lib/data/carouselFallback.ts (and the fallback line in content.ts).

Review

Verdict: ALL CLEAR
Rounds: 2

Rebased onto main after #51 (no conflicts) and pushed with --force-with-lease pinned to 6972d9b.

Finding Severity Resolution
Animated GIF stored as one tall JPEG of every frame (row says 300x200, file is 300x600); SVG accepted by image/* warning fixed in 5ea9c4e
A file picked while an earlier one compresses is replaced by the earlier file on save warning fixed in 247afda
Animated WebP through the API still stored as a frame strip suggestion open: rare, API only; the admin keeps the first frame, and rejecting WebP would hide it from the admin picker
Transparent PNG flattened on black through the API, white in the admin suggestion open: follows the ticket's JPEG decision; Payload's formatOptions has no background option
AC3 enforced per locale, not both in one save suggestion open: Payload's admin edits one locale per save, so the strict reading would block adding any photo; French falls back to the English alt

Re-verified: AC4 and AC5 (deploy, rebuilt preview 247afda: 11.93 MB JPEG "Compressed in the browser: 11.93 MB to 514 KB.", POST 201; media row photo12.jpg image/jpeg 2560x1920 481618; bucket photo12.jpg 481618) PASS, AC7 (browser, admin: notes.txt and anim.gif POST 400, accept image/jpeg, image/png, image/webp) PASS, AC4 (browser, production build: 13.71 MB JPEG compressed in the browser, POST 201, stored image/jpeg 2560x1920) PASS, codec-blocked fallback (browser) PASS, AC8 (browser: live region and arrow keys) PASS, /about fallback on a production build reading preview reset from main (four repo images, EN and FR, 1280 and 390, no console errors) PASS, migration up/down/up on preview reset from main PASS, migrate:create: "No schema changes detected" PASS · check.sh PASS

Evidence

AC1

Before is production (https://clarksbowlingclub.com), after is this branch on dev after pnpm content:import. Alt texts are read from the rendered <img> elements.

before 1280 en ["Band portrait inside an abandoned warehouse","Band posing together in dilapidated building","Band leaving the warehouse after rehearsal and shoot","Still of the band in Yes Day music video shoot"] noerr
after  1280 en (same four, same order) noerr
after  1280 fr (same four, same order) noerr
after  390  en (same four, same order) noerr
after  390  fr (same four, same order) noerr
carousel: 4 photos imported
carousel: 4 photos already there, skipped        (second run)

The French page showed the English alt texts before and still does: the hard-coded list had one language.

AC2

add fifth: 200 5 rows         -> page alts end with 'Fifth photo' (1.5 s later, no redeploy)
reorder (reverse): 200 5 rows -> page alts in reverse order
remove first: 200 4 rows      -> page shows the remaining four

AC3

empty en alt: 400 carousel.0.alt   This field is required.
empty fr alt: 400 carousel.0.alt   This field is required.
no photo:     400 carousel.0.photo This field is required.

AC4 and AC5

On https://deploy-preview-53--clarksbowlingclub.netlify.app/admin, headless Chromium, media create page, test files of 18.5 MB (JPEG) and 22.9 MB (PNG), both above the 12 MB asked for:

phone.jpg: note "Compressed in the browser: 17.70 MB to 377 KB."  POST body bytes 386346  status 201 "Media successfully created."
large.png: note "Compressed in the browser: 21.80 MB to 400 KB."  POST body bytes 409650  status 201 "Media successfully created."

neon psql preview: select id,filename,mime_type,width,height,filesize from media
1|phone.jpg|image/jpeg|2560|1707|345104
2|large.jpg|image/jpeg|2560|1707|348783

neon bucket object list media --branch preview
phone.jpg  345104
large.jpg  348783

With the carousel global empty, the preview's /about still renders the four repo images (/_next/image?url=%2Fimages%2Fcarousel%2Fargentic.jpg, posing, leaving, yesday), so production keeps its photos until the band uploads.

AC6

POST /api/media  phone.jpg 18.5 MB -> phone-3.jpg image/jpeg 2560x1707 468273 bytes
POST /api/media  api.png 17.5 MB noise PNG -> api.jpg image/jpeg 2560x1829 1869731 bytes

The PNG is random noise, which does not compress; real photos land well under 1 MB.

AC7

POST /api/media notes.txt -> 400 "File type text/plain (from extension txt) is not allowed."
admin create page, notes.txt chosen -> POST 400, same message; nothing saved

AC8

live: Image 1 of 4: ...   after ArrowRight: Image 2 of 4: ...   after 2x ArrowLeft: Image 4 of 4: ... (wraps)
figcaption: Band photo gallery
diff of src/components/ui/Carousel.tsx against main: empty (reduced-motion paths unchanged)

Migration on production's state

neon branches reset preview --parent, then with the preview env loaded (NEON_BRANCH=preview):

migrate:status   initial Yes, calendar Yes, calendar_checks Yes, carousel No
Migrated:  20261113_001547_carousel (115ms)
Migrated down:  20261113_001547_carousel (45ms)   -> to_regclass('about_page_carousel') empty
Migrated:  20261113_001547_carousel (44ms)        -> about_page_carousel | about_page_carousel_locales
insert ... photo_id 999999 -> violates foreign key constraint "about_page_carousel_photo_id_media_id_fk"
insert ... photo_id null   -> violates not-null constraint

Compression in the browser (production build)

admin /media/create, phone.jpg 18.5 MB: "Compressed in the browser: 17.70 MB to 377 KB."  POST body bytes 386346  status 201
admin /media/create, large.png 22.9 MB:  POST body bytes 409650  status 201
codec blocked (wasm aborted): "This browser could not compress the image, so the original will be uploaded..."  status 201
Content-Security-Policy on /admin/login: script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'
Content-Security-Policy on /about:       script-src 'self' 'unsafe-inline'

@netlify

netlify Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for clarksbowlingclub ready!

Name Link
🔨 Latest commit 247afda
🔍 Latest deploy log https://app.netlify.com/projects/clarksbowlingclub/deploys/6af65e511bf7c4272ba31bd2
😎 Deploy Preview https://deploy-preview-53--clarksbowlingclub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@maxitect
maxitect force-pushed the feat/43-carousel-photos-in-payload-with-images-compressed branch from 6972d9b to 247afda Compare November 13, 2026 00:48
@maxitect
maxitect marked this pull request as ready for review November 13, 2026 00:51
@maxitect
maxitect merged commit 7c48a48 into main Nov 13, 2026
5 checks passed
@maxitect
maxitect deleted the feat/43-carousel-photos-in-payload-with-images-compressed branch November 13, 2026 00:51
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.

Carousel photos in Payload, with images compressed on upload

1 participant