fix(useDataLoader): cancel in-flight section fetches when company changes (P2-45)
Add currentCompanyId to effect deps so switching company aborts the previous company's pending inbox/metrics/standup fetches before stale results can overwrite new state.
This commit is contained in:
1 parent
83462a4663
commit
67035d1a8e
1 file changed
+7
-5
@@ -36,10 +36,12 @@ export function useDataLoader(
|
|||||||
}
|
}
|
||||||
}, [selectedConnectorId, selectedRunId]);
|
}, [selectedConnectorId, selectedRunId]);
|
||||||
|
|
||||||
// Section-based data loading
|
// Section-based data loading; resets when section OR company changes so
|
||||||
|
// in-flight requests for the previous company cannot overwrite new state.
|
||||||
|
const currentCompanyId = snapshot?.currentCompanyId ?? null;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!snapshot?.currentCompanyId) return;
|
if (!currentCompanyId) return;
|
||||||
const companyId = snapshot.currentCompanyId;
|
const companyId = currentCompanyId;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
const store = useAppStore.getState();
|
const store = useAppStore.getState();
|
||||||
|
|
||||||
@@ -62,13 +64,13 @@ export function useDataLoader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (section === "social") {
|
if (section === "social") {
|
||||||
store.setSocialAccounts(snapshot.socialAccounts?.filter((a) => a.companyId === companyId) ?? []);
|
store.setSocialAccounts(snapshot?.socialAccounts?.filter((a) => a.companyId === companyId) ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [section, snapshot]);
|
}, [section, currentCompanyId, snapshot]);
|
||||||
|
|
||||||
return { refresh };
|
return { refresh };
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user