Skip to content

diagram: selection-mutating Editor handlers bypass handleSelection, skipping showDetails reset and onSelectionChanged #529

Closed

Description

@bpowers

Summary

src/diagram/Editor.tsx has a single canonical selection-change handler, handleSelection(selection: ReadonlySet<UID>) (around line 699), which does three things:

  1. setState({ selection, flowStillBeingCreated: false, variableDetailsActiveTab: 0 })
  2. When the new selection is empty, also setState({ showDetails: undefined }) -- resets the variable-details panel state.
  3. Notifies the optional onSelectionChanged?: (idents: string[]) => void prop via a deferred setTimeout(..., 0) that reads getSelectionIdents() after React commits the new selection.

Several other handlers mutate state.selection directly via setState/setStateForView instead of routing through handleSelection, so they skip steps 2 and/or 3:

  • handleSelectionDelete (around line 747, clears at ~line 816-818): this.setState({ selection: new Set<number>() }). Leaves showDetails at whatever it was (e.g. 'variable') even though there is no selection, and does not notify onSelectionChanged that the selection was cleared by the delete.
  • handleFlowAttach (around line 835, clears at ~line 1369): sets selection: new Set<number>() -- no showDetails reset, no onSelectionChanged.
  • handleSelectionMove (around line 1373) and the undo/redo path (around line 1814) -- set showDetails: undefined but do not notify onSelectionChanged.
  • handleNavigateBack / handleNavigateToLevel (around lines 1823 / 1848) -- restore the parent's selection and do set showDetails: undefined, but do not notify onSelectionChanged.

Why it matters

  • Stale UI state: After handleSelectionDelete, state.showDetails can remain 'variable' with an empty selection -- an inconsistent state. Currently masked because getVariableDetails() also checks getNamedSelectedElement() (returns undefined for an empty selection), so the panel doesn't render -- but the state is wrong and a future change to that render guard would surface it.
  • Broken host contract: onSelectionChanged is documented (see src/diagram/CLAUDE.md) as firing "after each selection change" and is consumed by simlin-serve's EditorHost to forward selection state to backend listeners. Hosts that subscribe are not told the selection was cleared when the user deletes the selected element(s), or when navigating in/out of modules. src/app's HostedWebEditor does not subscribe, so the web app is unaffected, but the contract is violated for serve and any other subscriber.

Component(s) affected

  • src/diagram -- Editor.tsx (handleSelection, handleSelectionDelete, handleFlowAttach, handleSelectionMove, handleNavigateBack, handleNavigateToLevel, undo/redo handler)
  • Downstream: src/simlin-serve EditorHost (subscriber to onSelectionChanged)

Possible approach

Route all state.selection mutations through a single helper (or through handleSelection itself) so the showDetails-reset-on-empty and the deferred onSelectionChanged notification happen consistently. Handlers that also need to set view state can compose the selection helper with their own setState. At minimum, handleSelectionDelete should clear showDetails and notify onSelectionChanged when it empties the selection.

Care needed around the existing selectionDeferralTimer bookkeeping (instance field cancelled in componentWillUnmount, superseded by newer selections) so consolidation doesn't introduce duplicate or lost notifications.

How discovered

Noticed while fixing an unrelated bug in src/diagram/Editor.tsx -- pre-existing inconsistency between handleSelectionDelete and handleSelection.

Activity

  1. added
    frontend
    bug
    on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfrontend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions