fix(gallery): admin edits to welcome_message land for returning guests (#625)

GalleryAuthContext cached the event in sessionStorage on first visit and
then SKIPPED the server fetch on returning visits (`if (!storedEvent)`),
so a guest who'd already opened the gallery would never see admin edits
to welcome_message / event_name / hero_logo / colour theme — sessionStorage
survives Cmd+Shift+R, so the only escape was closing the tab or wiping
site data manually.

The cached event is still shown above as an instant placeholder for
perceived perf, but the server fetch is no longer gated: on every mount
the fresh row overwrites both React state and the sessionStorage entry.
Cost is one extra /gallery/:slug/photos request per gallery navigation
when the session is already authenticated; benefit is admin edits
propagating on next page load for everyone.
This commit is contained in:
Paul Nothaft
2026-06-17 22:47:48 +02:00
parent 178d6dafb1
commit ea6245cfde
+13 -8
View File
@@ -212,14 +212,19 @@ export const GalleryAuthProvider: React.FC<GalleryAuthProviderProps> = ({ childr
if (sessionResponse.data?.valid && sessionResponse.data.type === 'gallery' && sessionResponse.data.eventSlug === currentSlug) {
setIsAuthenticated(true);
if (!storedEvent) {
const galleryData = await galleryService.getGalleryPhotos(currentSlug);
if (galleryData?.event) {
const normalizedEvent = normalizeEvent(galleryData.event);
setEvent(normalizedEvent);
if (normalizedEvent) {
sessionStorage.setItem(`gallery_event_${currentSlug}`, JSON.stringify(normalizedEvent));
}
// Always refresh from the server — the stored event from sessionStorage
// is shown above as an instant placeholder for perceived perf, but it
// must NOT win permanently: admin edits to welcome_message / event_name /
// hero_logo / colour theme need to land on the next page load for
// returning guests. sessionStorage survives Cmd+Shift+R, so without
// this refresh the cache could only be cleared by closing the tab or
// wiping site data manually (#625).
const galleryData = await galleryService.getGalleryPhotos(currentSlug);
if (galleryData?.event) {
const normalizedEvent = normalizeEvent(galleryData.event);
setEvent(normalizedEvent);
if (normalizedEvent) {
sessionStorage.setItem(`gallery_event_${currentSlug}`, JSON.stringify(normalizedEvent));
}
}