Keep auxiliary previews stable on unchanged background refreshes

This commit is contained in:
syntaxbullet
2026-09-08 16:27:03 +02:00
parent 03eb8d9e7a
commit c91202bbfc

View File

@@ -163,6 +163,8 @@ function Welcome({ onSignIn }: { onSignIn: () => void }) {
function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => void }) { function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => void }) {
const [today, setToday] = useState<TodayResponse | null>(null); const [today, setToday] = useState<TodayResponse | null>(null);
const todaySnapshot = useRef(today);
todaySnapshot.current = today;
const [error, setError] = useState(""); const [error, setError] = useState("");
const [revision, setRevision] = useState(0); const [revision, setRevision] = useState(0);
const [habitRevisions, setHabitRevisions] = useState<Record<string, number>>({}); const [habitRevisions, setHabitRevisions] = useState<Record<string, number>>({});
@@ -204,9 +206,10 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
habitRequest<TodayResponse>("/today", { signal: controller.signal }) habitRequest<TodayResponse>("/today", { signal: controller.signal })
.then((data) => { .then((data) => {
if (!controller.signal.aborted) { if (!controller.signal.aborted) {
setToday(current => reconcileToday(current, data)); const next = reconcileToday(todaySnapshot.current, data);
setToday(next);
setNeedsRefresh(false); setNeedsRefresh(false);
setRevision((value) => value + 1); if (next !== todaySnapshot.current) setRevision((value) => value + 1);
} }
}) })
.catch((error) => { .catch((error) => {