A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
fix(frontend): resolve remaining react-hooks rules (purity, immutability, memoization)
dextmorgn695fdff4a0f3
diff --git a/flowsint-app/src/components/analyses/editor/hooks/use-throttle.ts b/flowsint-app/src/components/analyses/editor/hooks/use-throttle.tsindex f3f88fba..88c23ec2 100644--- a/flowsint-app/src/components/analyses/editor/hooks/use-throttle.ts+++ b/flowsint-app/src/components/analyses/editor/hooks/use-throttle.ts@@ -4,7 +4,13 @@ export function useThrottle<T extends (...args: any[]) => void>(callback: T,delay: number): (...args: Parameters<T>) => void {- const lastRan = useRef(Date.now())+ // Date.now() is impure to call during render, even guarded — start at 0+ // instead of a captured mount timestamp. Only changes behavior for a call+ // within `delay`ms of mount, and even then it's arguably more correct:+ // 0 means "nothing has run yet", so the very first call fires immediately+ // (the standard leading-edge throttle behavior) rather than being held+ // back by an arbitrary mount-time baseline.+ const lastRan = useRef(0)const timeoutRef = useRef<NodeJS.Timeout | null>(null)return useCallback(diff --git a/flowsint-app/src/components/investigations/sketch-list.tsx b/flowsint-app/src/components/investigations/sketch-list.tsxindex 8a710e70..8a09ba3b 100644--- a/flowsint-app/src/components/investigations/sketch-list.tsx+++ b/flowsint-app/src/components/investigations/sketch-list.tsx@@ -33,7 +33,7 @@ const SketchList = () => {return investigation.sketches.filter((sketch: Sketch) =>sketch.title.toLowerCase().includes(query))- }, [investigation?.sketches, searchQuery])+ }, [investigation, searchQuery])if (error)return (@@ -70,6 +70,7 @@ const SketchList = () => {<ul className="p-2">{filteredSketches.map((sketch: Sketch) => (<Link+ key={sketch.id}to="/dashboard/investigations/$investigationId/$type/$id"params={{investigationId: sketch.investigation_id,diff --git a/flowsint-app/src/components/shared/icon-picker/popup.tsx b/flowsint-app/src/components/shared/icon-picker/popup.tsxindex 66f5d54e..558e4ecf 100644--- a/flowsint-app/src/components/shared/icon-picker/popup.tsx+++ b/flowsint-app/src/components/shared/icon-picker/popup.tsx@@ -256,6 +256,11 @@ export default function IconPicker({ iconType, open, setOpen, onIconChange }: Icconst rows = Math.ceil(filteredIcons.length / COLUMNS)+ // TanStack Virtual's useVirtualizer() is a documented React Compiler+ // incompatibility (it returns functions that can't be safely memoized) —+ // there's no code change here that fixes it, the compiler correctly skips+ // optimizing this component.+ // eslint-disable-next-line react-hooks/incompatible-libraryconst virtualizer = useVirtualizer({count: rows,getScrollElement: () => parentRef.current,diff --git a/flowsint-app/src/components/sketches/details-panel/details-panel.tsx b/flowsint-app/src/components/sketches/details-panel/details-panel.tsxindex f3e3da70..7c9826de 100644--- a/flowsint-app/src/components/sketches/details-panel/details-panel.tsx+++ b/flowsint-app/src/components/sketches/details-panel/details-panel.tsx@@ -405,7 +405,7 @@ const DetailsPanel = memo(() => {setFormData(newFd)saveState(newFd, nodeSizeRef.current)},- [saveState]+ [saveState, setFormData])const handleChange = useCallback(@@ -415,7 +415,7 @@ const DetailsPanel = memo(() => {setFormData(newFd)saveState(newFd, nodeSizeRef.current)},- [saveState]+ [saveState, setFormData])const handlePropertyBlur = useCallback(@@ -448,7 +448,7 @@ const DetailsPanel = memo(() => {setFormData(newFd)scheduleSave(newFd, nodeSizeRef.current)},- [scheduleSave]+ [scheduleSave, setFormData])const handleIconSelect = useCallback(@@ -458,7 +458,7 @@ const DetailsPanel = memo(() => {setFormData(newFd)saveState(newFd, nodeSizeRef.current)},- [saveState]+ [saveState, setFormData])const copyField = (value: any): string | undefined => {diff --git a/flowsint-app/src/components/sketches/graph/node/actions/flag.tsx b/flowsint-app/src/components/sketches/graph/node/actions/flag.tsxindex bcc24d2e..c075faff 100644--- a/flowsint-app/src/components/sketches/graph/node/actions/flag.tsx+++ b/flowsint-app/src/components/sketches/graph/node/actions/flag.tsx@@ -41,7 +41,6 @@ export function NodeFlag({ sketchId, node }: { sketchId: string; node: GraphNodeasync (value: string) => {// Click the same color and it removes itconst val = value === flagValue ? null : (value as flagColor)- node.nodeFlag = flagValuesetFlagValue(val)try {updateNode(nodeId, { nodeFlag: val })diff --git a/flowsint-app/src/components/sketches/graph/node/actions/node-actions.tsx b/flowsint-app/src/components/sketches/graph/node/actions/node-actions.tsxindex 40f0c778..63fa0b57 100644--- a/flowsint-app/src/components/sketches/graph/node/actions/node-actions.tsx+++ b/flowsint-app/src/components/sketches/graph/node/actions/node-actions.tsx@@ -92,7 +92,6 @@ const NodeActions = memo(const handleUpdateFlag = useCallback(async (value: FlagColor) => {const val = value === flagValue ? null : value- node.nodeFlag = flagValuesetFlagValue(val)try {updateNode(node.id, { nodeFlag: val })diff --git a/flowsint-app/src/components/table/nodes-view.tsx b/flowsint-app/src/components/table/nodes-view.tsxindex aa452dfa..18b55353 100644--- a/flowsint-app/src/components/table/nodes-view.tsx+++ b/flowsint-app/src/components/table/nodes-view.tsx@@ -226,6 +226,11 @@ export default function NodesTable({ nodes }: NodesTableProps) {return Array.from(types).sort()}, [nodes])+ // TanStack Virtual's useVirtualizer() is a documented React Compiler+ // incompatibility (it returns functions that can't be safely memoized) —+ // there's no code change here that fixes it, the compiler correctly skips+ // optimizing this component.+ // eslint-disable-next-line react-hooks/incompatible-libraryconst virtualizer = useVirtualizer({count: filteredNodes.length,getScrollElement: () => parentRef.current,diff --git a/flowsint-app/src/components/table/relationships-view.tsx b/flowsint-app/src/components/table/relationships-view.tsxindex 85576513..b6dc8603 100644--- a/flowsint-app/src/components/table/relationships-view.tsx+++ b/flowsint-app/src/components/table/relationships-view.tsx@@ -278,6 +278,11 @@ export default function RelationshipsTable() {)}, [selectedEdges, sketchId, confirm, removeEdges, clearSelectedEdges, refetch])+ // TanStack Virtual's useVirtualizer() is a documented React Compiler+ // incompatibility (it returns functions that can't be safely memoized) —+ // there's no code change here that fixes it, the compiler correctly skips+ // optimizing this component.+ // eslint-disable-next-line react-hooks/incompatible-libraryconst virtualizer = useVirtualizer({count: filteredRelationships.length,getScrollElement: () => parentRef.current,diff --git a/flowsint-app/src/components/ui/sidebar.tsx b/flowsint-app/src/components/ui/sidebar.tsxindex 27ac5f16..9550d147 100644--- a/flowsint-app/src/components/ui/sidebar.tsx+++ b/flowsint-app/src/components/ui/sidebar.tsx@@ -580,10 +580,11 @@ function SidebarMenuSkeleton({}: React.ComponentProps<'div'> & {showIcon?: boolean}) {- // Random width between 50 to 90%.- const width = React.useMemo(() => {- return `${Math.floor(Math.random() * 40) + 50}%`- }, [])+ // Random width between 50 to 90%, picked once and kept stable for this+ // instance's lifetime. useMemo doesn't actually guarantee that (React+ // treats it as a cache, not a correctness contract) — useState's lazy+ // initializer does.+ const [width] = React.useState(() => `${Math.floor(Math.random() * 40) + 50}%`)return (<div