fix(#947): poll ALL staging queries while scanning, not just files

Re-review caught a real bug in the phase-2 polling: it refetched only the files query, but the
album import tab uses its OWN groups query (album-import-tab.tsx). So after a large-folder scan
completed, the album tab would stay stuck on its initial {scanning} response and never populate
(the singles tab was fine — it reads the polled files query). Switched the scan poll to
invalidateImportStagingQueries (files + groups + suggestions) so every mounted staging query
refetches when the scan finishes. (Suggestions is already async/cached, so it just no-ops.)

typecheck clean, scanning test still passes.
This commit is contained in:
BoulderBadgeDad 2026-06-29 10:03:14 -07:00
parent 8f1ffa7632
commit f746fb4fc4

View file

@ -22,19 +22,20 @@ export function useImportStaging() {
});
// A large staging folder (whole-library migration, #947) is scanned in the background; the
// endpoint returns `scanning: true` until it's done. While scanning, poll so the page fills
// in automatically once the scan completes. A plain setInterval (NOT react-query's
// refetchInterval, which interferes with the data query's error/retry settling) that only
// runs while scanning, so the normal and error states are left completely untouched.
// endpoints return `scanning: true` until it's done. While scanning, poll so the page fills
// in automatically once the scan completes. Invalidate ALL staging queries (files, groups,
// suggestions) — not just files — so the album tab's separate groups query refetches too,
// otherwise it would stay stuck on its initial {scanning} response. A plain setInterval (NOT
// react-query's refetchInterval) that only runs while scanning leaves normal/error states
// untouched; only currently-mounted queries actually refetch.
const scanning = stagingQuery.data?.scanning === true;
const { refetch } = stagingQuery;
useEffect(() => {
if (!scanning) return undefined;
const id = window.setInterval(() => {
void refetch();
void invalidateImportStagingQueries(queryClient);
}, 1500);
return () => window.clearInterval(id);
}, [scanning, refetch]);
}, [scanning, queryClient]);
return {
refreshStaging: async () => {