Description
handleClose is wrapped in useCallback with only [onClose] as dependency, but internally calls resetForm() which references multiple state variables (setMode, setBatchRows, etc.). When switching between modes (single→batch→single) and closing, resetForm() may use stale closure values.
Location
dashboard/src/components/CreateSessionModal.tsx lines ~36-40:
const handleClose = useCallback((): void => {
resetForm();
onClose();
}, [onClose]);
resetForm is a regular function that reads state setters (which are stable), but the pattern is fragile. If resetForm is ever changed to read state values instead of just setting them, this will silently break.
Risk
Currently the practical impact is low because resetForm only calls setters. But:
- The Escape key handler and backdrop click both depend on this closure
- If batch results are showing and user closes,
batchResult state persists incorrectly on next open
Fix
Either:
- Move
resetForm inside useCallback (inline the resets), OR
- Add
resetForm to the dependency array (wrap it in useCallback too), OR
- Use a ref for the reset function
Environment
- Aegis Dashboard (all versions with batch mode)
Description
handleCloseis wrapped inuseCallbackwith only[onClose]as dependency, but internally callsresetForm()which references multiple state variables (setMode,setBatchRows, etc.). When switching between modes (single→batch→single) and closing,resetForm()may use stale closure values.Location
dashboard/src/components/CreateSessionModal.tsxlines ~36-40:resetFormis a regular function that reads state setters (which are stable), but the pattern is fragile. IfresetFormis ever changed to read state values instead of just setting them, this will silently break.Risk
Currently the practical impact is low because
resetFormonly calls setters. But:batchResultstate persists incorrectly on next openFix
Either:
resetForminsideuseCallback(inline the resets), ORresetFormto the dependency array (wrap it in useCallback too), OREnvironment