fix: update baseline logic in useDocuments and useInbox hooks to accurately track new items and unread counts, addressing timing issues with Electric updates

This commit is contained in:
Anish Sarkar 2026-03-06 20:21:28 +05:30
parent 1a688c7161
commit 3e4db20bcb
3 changed files with 41 additions and 17 deletions

View file

@ -351,12 +351,14 @@ export function useDocuments(
const liveIds = new Set(validItems.map((d) => d.id));
const prevIds = new Set(prev.map((d) => d.id));
// First callback: snapshot all Electric IDs as the baseline.
// Everything in this set existed before the sidebar opened and
// should only appear via API pagination, not Electric.
if (electricBaselineIdsRef.current === null) {
electricBaselineIdsRef.current = new Set(liveIds);
}
// Only baseline items already rendered from API.
// Items in Electric but NOT in prev are genuinely new
// (created between the API fetch and Electric's first callback).
if (electricBaselineIdsRef.current === null) {
electricBaselineIdsRef.current = new Set(
[...liveIds].filter((id) => prevIds.has(id))
);
}
// Genuinely new = not in rendered list, not in baseline snapshot.
// These are docs created AFTER the sidebar opened.