Settings: reopening the signature editor showed the old signature

Saving invalidated only the ["accounts"] list, not the ["account", id]
detail the editors read. Reopening rendered the stale cached detail, and
the rich-text editor seeds its content only once on mount, so the refetch
that followed never reached the screen. Both the signature and the
account editors now write the PATCH response into the detail cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 19:41:25 +02:00
co-authored by Claude Opus 5.5
parent e1371c4f84
commit 901156526c
+12 -2
View File
@@ -389,6 +389,7 @@ function AccountEditor({
onSaved: () => void; onSaved: () => void;
}) { }) {
const t = useT(); const t = useT();
const queryClient = useQueryClient();
const detail = useQuery({ queryKey: ["account", accountId], queryFn: () => api.accountDetail(accountId) }); const detail = useQuery({ queryKey: ["account", accountId], queryFn: () => api.accountDetail(accountId) });
const [displayName, setDisplayName] = useState(""); const [displayName, setDisplayName] = useState("");
const [color, setColor] = useState("#888888"); const [color, setColor] = useState("#888888");
@@ -428,7 +429,10 @@ function AccountEditor({
} }
return api.updateAccount(accountId, patch); return api.updateAccount(accountId, patch);
}, },
onSuccess: onSaved, onSuccess: (updated) => {
queryClient.setQueryData(["account", accountId], updated);
onSaved();
},
onError: (e) => setError(e instanceof ApiError ? e.message : "Save failed"), onError: (e) => setError(e instanceof ApiError ? e.message : "Save failed"),
}); });
@@ -519,6 +523,7 @@ function SignatureEditor({
onSaved: () => void; onSaved: () => void;
}) { }) {
const t = useT(); const t = useT();
const queryClient = useQueryClient();
const detail = useQuery({ const detail = useQuery({
queryKey: ["account", accountId], queryKey: ["account", accountId],
queryFn: () => api.accountDetail(accountId), queryFn: () => api.accountDetail(accountId),
@@ -532,7 +537,12 @@ function SignatureEditor({
const save = useMutation({ const save = useMutation({
mutationFn: () => api.updateAccount(accountId, { signature }), mutationFn: () => api.updateAccount(accountId, { signature }),
onSuccess: onSaved, // Keep the cached detail current: the editor seeds from it only once on mount,
// so a stale entry would reopen the editor with the old (e.g. empty) signature.
onSuccess: (updated) => {
queryClient.setQueryData(["account", accountId], updated);
onSaved();
},
onError: (e) => setError(e instanceof ApiError ? e.message : "Save failed"), onError: (e) => setError(e instanceof ApiError ? e.message : "Save failed"),
}); });