fix(cli): suppress react-hooks/set-state-in-effect for load-on-mount pattern (plan 14)

Pre-existing lint error from F8 commit 2d58519ca9 — the new react-hooks/set-state-in-effect rule conservatively flags any setState within useEffect body, even when setState happens async after Promise resolution. The "load remote data on mount" pattern is canonical until React 19 use()/Suspense migration.

Fix adds cancelled-flag pattern to prevent setState after unmount + block-disable with justification comment. Tests still pass 5/5.

Found during code review v2 deep audit — F10 audit reported "lint 0 errors" but only ran focused lint, not full project (which surfaces ~2985 pre-existing warnings + this 1 new error).
This commit is contained in:
diegosouzapw
2026-05-28 13:58:54 -03:00
parent 77b055aba0
commit 27d4a7aeac

View File

@@ -84,12 +84,25 @@ export default function ToolDetailClient({ toolId, category }: ToolDetailClientP
}, []);
useEffect(() => {
let cancelled = false;
// "Load data on mount" pattern: fetch* callbacks call setState internally
// after async resolution. The cancelled flag prevents setState after unmount.
// The react-hooks/set-state-in-effect rule flags this pattern conservatively
// (it cannot distinguish sync vs async setState), but this is the canonical
// way to load remote data on mount until we migrate to use()/Suspense.
/* eslint-disable react-hooks/set-state-in-effect */
Promise.all([
fetchConnections(),
fetchApiKeys(),
fetchCloudSettings(),
fetchDynamicModels(),
]).finally(() => setLoading(false));
]).finally(() => {
if (!cancelled) setLoading(false);
});
/* eslint-enable react-hooks/set-state-in-effect */
return () => {
cancelled = true;
};
}, [fetchConnections, fetchApiKeys, fetchCloudSettings, fetchDynamicModels]);
const getActiveProviders = useCallback(() => {