Skip to content

bug(dashboard): CreateSessionModal handleClose uses stale state via useCallback missing dependency #4402

@OneStepAt4time

Description

@OneStepAt4time

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:

  1. Move resetForm inside useCallback (inline the resets), OR
  2. Add resetForm to the dependency array (wrap it in useCallback too), OR
  3. Use a ref for the reset function

Environment

  • Aegis Dashboard (all versions with batch mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugSomething isn't workingdashboardreadyTriaged and ready for an agent to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions