BUG: live preview broken after #28 (gallery) — likely JS halt in media preview wiring #30
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug (regression from #28, live on sendmy.cards)
m: „jetzt klappt das preview nicht mehr.“ The #15 live card preview stopped working after the #28 gallery merge.
otto-head diagnosis (head start)
#28 added the media-source toggle (
media_source= upload | gallery) and a gallery grid to compose. The preview JS (compose.html ~L269+) still wires the unified upload input: around L320 it doesmediaInput.addEventListener('change', …). Strong suspicion: with the new toggle,mediaInputcan be null / not present in some state (e.g. whenmedia_source=gallery, or the input got restructured), so the script throws early — and a single uncaught exception there halts the WHOLE inline script, killing not just media preview but the card preview (#previewSection/#cardPreview), the Wunsch-Adresse URL preview, and the occasion→theme live updates too. That matches 'preview doesn't work anymore'.Fix
mediaInputexists; guard every getElementById/querySelector before addEventListener).#cardPreview(image from the asset URL), same as an uploaded file. Switching the source toggle should refresh the preview.Constraints
CSS/JS/markup only (no backend/schema change expected). Mobile-first, German. No regression to #15 (preview), #24/#25 (styling), #28 (gallery), occasion→theme, URL preview.
DoD
Fixed — root cause was a JS halt, but not where the head guessed
Reproduced in headless Chromium (playwright). The console showed the real error:
mediaInputis not the culprit —#mediais emitted unconditionally, so it's never null. The actual halt was a temporal-dead-zone error:Bug 1 (primary halt) —
radioValused before itsconstdeclarationThe gallery init calls
filterGallery()at load (compose.html), which callsradioVal('occasion'). ButradioVal/el/todayStrwere declared asconstafter the gallery block.constisn't hoisted (TDZ), so the call threw — a single uncaught error that halted the whole inline script and killed every live preview: card preview, media thumbnails, URL preview, occasion→theme. It only fires whenGalleryAssetsexist, i.e. exactly the live state after #28. That's why „das preview klappt nicht mehr“.Bug 2 (co-regression) — slug
.segshadowed by the new media-source.seg#28 added
<div class="seg media-source">, which now precedes the slug<div class="seg" data-base=...>in the DOM.querySelector('.seg')therefore bound the URL-preview block to the wrong element, leaving theto/·from/prefix radios unwired. Now selected via.seg[data-base].Fix (CSS/JS/markup only — no backend/schema change)
el/radioVal/todayStr) above all feature blocks; all shared state/functions live at module scope.mediaInput/preview/videoPreview).block()wrapper so a fault in one feature is logged to console but can't halt the others (resilient inline script, per DoD point 4).Verification (playwright, headless Chromium)
Faithful harness with the real inline script + gallery markup. Results:
ReferenceError: radioVal×4to/oma-erika,from/test✔gallery_asset_idwrittendusk+ 🎄 Weihnachtengo build ./...green ·go test ./internal/server/...green.Both upload and gallery source modes work; switching source/occasion updates the preview; no JS console errors. Ready for otto-head to merge + deploy.
Commit:
cbab605a7cBranch:
mai/hermes/issue-30-bug-live✅ Merged & deployed (merge
ad416c4)Root cause: a TDZ ReferenceError (
radioValused before itsconst, only triggered once gallery assets exist = post-#28) halted the whole inline compose script — plus a co-regression where the new.seg media-sourceshadowed the slug.segquerySelector. Both fixed: helpers hoisted, null-guards, each enhancement isolated in ablock()wrapper so one fault can't kill the others, slug seg selected via.seg[data-base]. Verified in headless Chromium (playwright). JS/markup only. build green. Please confirm the preview works for you again. Not closing — m closes.