From 401abf7a27cb73dd7fb8399f4c05644c95767093 Mon Sep 17 00:00:00 2001 From: Paul Nothaft Date: Thu, 7 May 2026 22:41:44 +0200 Subject: [PATCH] =?UTF-8?q?fix(create-event):=20re-apply=20Branding=20them?= =?UTF-8?q?e=20on=20stale=E2=86=92fresh=20settings=20(#323-B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CreateEventPage's branding-default effect used a boolean ref guard that locked in whichever theme_config arrived first. React Query can hand the observer a cached (stale) copy on initial render and then push fresh data once the network call resolves — the boolean ref meant the form kept the stale theme and ignored the fresh one. Replace the ref with a stringified-hash check: re-apply when the source actually changes (including stale → fresh) but skip when nothing has. User edits via the customizer aren't disturbed because settings.theme_config only refreshes on a real Branding save, not on form state. This unblocks the local pre-push smoke gate's 07-branding-default test, which was test.fixme'd against this exact React Query staleness. --- frontend/src/pages/admin/CreateEventPage.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/admin/CreateEventPage.tsx b/frontend/src/pages/admin/CreateEventPage.tsx index bec6863c..cf36ed86 100644 --- a/frontend/src/pages/admin/CreateEventPage.tsx +++ b/frontend/src/pages/admin/CreateEventPage.tsx @@ -245,12 +245,21 @@ export const CreateEventPage: React.FC = () => { // This is the "always inherit colours from Branding" guarantee — every new // gallery starts with the site palette unless the admin then picks a preset // or hits Sync from Branding inside the customizer to re-pull it later. - const brandingThemeApplied = useRef(false); + // + // Track the last theme_config we applied as a stringified hash rather than + // a boolean ref. React Query can hand us cached (stale) settings on first + // observer render and then push fresh data once the network call resolves; + // a boolean ref locks in the stale theme and ignores the fresh one (#323-B + // / smoke spec 07). With a hash, we re-apply when the source actually + // changes — including the stale → fresh transition — but skip when nothing + // new has arrived. + const lastAppliedThemeHashRef = useRef(null); useEffect(() => { - if (brandingThemeApplied.current) return; const brandingTheme = settings?.theme_config as ThemeConfig | undefined; if (!brandingTheme || Object.keys(brandingTheme).length === 0) return; - brandingThemeApplied.current = true; + const hash = JSON.stringify(brandingTheme); + if (lastAppliedThemeHashRef.current === hash) return; + lastAppliedThemeHashRef.current = hash; // Identify which preset (if any) the Branding theme matches. Compare // only on the preset's own fields so saved themes carrying extras