Keep auxiliary previews stable on unchanged background refreshes
This commit is contained in:
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user