Files
hermes-agent/apps
chenbin 41fd7847ad fix(desktop): stop context-menu item clicks from spurious preview open
Closes #101263

ContextMenuItem onSelect handlers (Copy path, Delete…, Reveal…) fire
their intended actions AND open the file preview — every menu item except
Rename… triggers onPreviewFile alongside its own action.

Root cause: Radix ContextMenu renders its portal content in document.body,
so clicks on menu items bubble as React synthetic fiber events (not DOM
events) to the nearest fiber ancestor — the row container div.  The
container's onClick=node.handleClick then fires onActivate →
onPreviewFile → openPreview for every menu item click.

A stopPropagation() wrapper before node.handleClick(e) does NOT stop
this: React dispatches the portal click directly onto the portal branch
of the fiber tree (there is no shared DOM bubble path through the row),
so the container's onClick still runs for it and the wrapper then calls
handleClick itself.

The Rename… flow already has a guard ($renamingPath) because it mounts an
inline input that would be immediately blurred by a preview panel opening.
The same guard cannot be applied broadly because single-click and
double-click legitimately need to activate previews.

Fix: only run arborist's handleClick when the click's DOM target is
actually inside the row container (e.currentTarget.contains(e.target)).
Portal-originated clicks — whose target lives in document.body, outside
the row — fail the containment check and are ignored. Real row clicks
(single, double, shift-attach) land inside the row's DOM and pass it.

review/file-tree.tsx is NOT affected: its menu wraps the row div as a
plain parent (no portal→fiber re-entry through the row), so it is left
untouched.

Regression test (tree.test.tsx) renders the real ProjectTree with the
real FileEntryContextMenu under jsdom: clicking "Copy path" in the
portaled menu must not call onPreviewFile (fails on main), while a real
single click still selects the row and a real double click still
previews the file (positive controls).
2026-09-30 23:07:23 -05:00
..