fix(spotlight): address PR review feedback

- Clear optimistic store on user/session change to prevent stale values leaking across logins
- Move dispatcher lookup before setOptimistic to avoid permanent ghost entries when no dispatcher exists
- Inline dayjs.weekdays() calls to reflect runtime locale changes instead of caching at module load
- Remove unused UserPreferenceKey import
This commit is contained in:
Thomas Camlong committed 2026-06-01 10:26:08 +02:00
1 parent e0a77948e2
commit 0449716805
3 files changed
+11 -7

No files matched your search

@@ -73,6 +73,13 @@ export const useUserPreferences = () => {
const t = useI18n();
const userId = session?.user.id;
const pendingRef = useRef<Record<string, boolean>>({});
const prevUserIdRef = useRef(userId);
useEffect(() => {
if (prevUserIdRef.current === userId) return;
prevUserIdRef.current = userId;
clearOptimistic(userPreferenceDefinitions.map((d) => d.key));
}, [userId]);
useSyncExternalStore(
subscribeOptimistic,
@@ -163,11 +170,12 @@ export const useUserPreferences = () => {
return;
}
setOptimistic(key, value);
const group = userPreferenceDefinitionByKey[key].mutationGroup!;
const dispatcher = groupDispatchers[group];
if (!dispatcher) return;
setOptimistic(key, value);
pendingRef.current[group] = true;
try {
await dispatcher(key, value);