fix(dashboard): stabilize cached snapshot references

Memoize cached dashboard snapshots so chart data stays referentially stable while live data loads. Add a regression test for cache-only parent rerenders to prevent the Recharts update loop when returning from canvas.
This commit is contained in:
2026-04-10 13:56:00 +02:00
parent 463830f178
commit 66646bd62f
2 changed files with 126 additions and 4 deletions

View File

@@ -20,10 +20,13 @@ export function useDashboardSnapshot(userId?: string | null): {
} {
const [cacheEpoch, setCacheEpoch] = useState(0);
const liveSnapshot = useAuthQuery(api.dashboard.getSnapshot, userId ? {} : "skip");
const cachedSnapshot =
userId && cacheEpoch >= 0
? readDashboardSnapshotCache<DashboardSnapshot>(userId)?.snapshot ?? null
: null;
const cachedSnapshot = useMemo(() => {
if (!userId || cacheEpoch < 0) {
return null;
}
return readDashboardSnapshotCache<DashboardSnapshot>(userId)?.snapshot ?? null;
}, [userId, cacheEpoch]);
useEffect(() => {
if (!userId || !liveSnapshot) return;