fix(create-event): branding-default theme survives eventTypes refetch

The "apply recommended preset on event-type change" effect was firing on
the initial mount AND every time the eventTypes API resolved (because
availableEventTypes is recomputed when that query settles). The first
fire matched the wedding default and clobbered the global Branding
theme that the previous effect had just applied.

Track the previous event_type in a ref and bail out when it hasn't
actually changed. The Branding-default effect now wins on first paint,
and the recommended-preset behaviour still kicks in when the user
manually picks a different event type.

Restores the green state of smoke spec 07 (#323-B regression).
This commit is contained in:
Paul Nothaft
2026-05-10 22:02:53 +02:00
parent 6ddb8e34d2
commit d62c529b02
+16 -4
View File
@@ -283,11 +283,23 @@ export const CreateEventPage: React.FC = () => {
}));
}, [settings]);
// Update theme when event type changes — but only when the event type has
// an explicit recommended preset. Skip the generic 'default' so the global
// Branding theme isn't clobbered by Classic Grid for event types like
// "Other" (#323).
// Update theme when the user actively changes the event type — but only
// when the new type has an explicit recommended preset. Skips both the
// generic 'default' (so types like "Other" don't clobber the global
// Branding theme with Classic Grid) and the very first render (so the
// wedding default doesn't out-race the Branding-default effect above
// when eventTypes resolves AFTER settings — #323-B / smoke spec 07).
const prevEventTypeRef = useRef<string | null>(null);
useEffect(() => {
const prev = prevEventTypeRef.current;
prevEventTypeRef.current = formData.event_type;
// First render: just record the initial value and let the
// Branding-default effect own the theme. Without this guard the
// initial-mount fire of this effect (and any later eventTypes
// refetch that swaps `availableEventTypes` identity) would
// overwrite the Branding theme with the wedding preset.
if (prev === null || prev === formData.event_type) return;
const selectedType = availableEventTypes.find(t => t.value === formData.event_type);
const recommendedPreset = selectedType?.theme_preset;