Skip to content

[trees] Fix sequential right-click closing the context menu (#664)#945

Draft
claude[bot] wants to merge 1 commit into
mainfrom
fix/664-sequential-right-click-context-menu
Draft

[trees] Fix sequential right-click closing the context menu (#664)#945
claude[bot] wants to merge 1 commit into
mainfrom
fix/664-sequential-right-click-context-menu

Conversation

@claude

@claude claude Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Requested by Alex · Slack thread

Description

Before: right-clicking a second file while the first file's context menu was open closed the menu entirely.

After: right-clicking a second file re-anchors the menu onto that file, matching the expected behavior in #664.

How: each opened menu now gets a monotonically increasing open-generation token stored on the menu state. When menu B opens (new token), the superseded menu A's consumer layer (Radix DropdownMenu onOpenChange) fires its close() asynchronously — previously this closed whatever menu was open, which was now menu B. Each context.close closure captures the token it was created with, and closeContextMenu no-ops when the captured token is no longer the active one, so a stale close from a superseded menu can no longer dismiss the menu that replaced it. No public API change.

Files touched:

  • packages/trees/src/render/FileTreeView.tsx — added the open-generation token to the context-menu state, bumped it on every open (openContextMenuForRow and the button-trigger path), guarded closeContextMenu with an optional expected token, and had the context.close closure pass its captured token.
  • packages/trees/test/file-tree-context-menu-sequential-right-click.test.ts — new jsdom regression test.

Motivation & Context

Fixes #664. Sequential right-clicks across different files should move the context menu, not dismiss it.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)

Testing

Added a jsdom regression test (file-tree-context-menu-sequential-right-click.test.ts) that opens the menu for row A, right-clicks row B, then fires menu A's captured (stale) close() after B has opened, and asserts the menu is still open and anchored to B.

  • Repro command: cd packages/trees && bun test test/file-tree-context-menu-sequential-right-click.test.ts
  • Before fix: fails — the stale close from menu A tears down menu B (expect(slotted).not.toBeNull() receives null).
  • After fix: passes (1 pass, 6 expect calls).
  • Full suite: cd packages/trees && bun test -> 325 pass / 0 fail across 29 files.
  • tsc --noEmit -p packages/trees/tsconfig.json -> clean.

Related issues

Fixes #664

Right-clicking file B while file A's context menu was open closed the
menu entirely instead of re-anchoring it onto B. When menu B opened, the
superseded menu A's consumer layer (Radix DropdownMenu onOpenChange)
fired its async close() and tore down menu B, because closeContextMenu
had no way to tell which menu instance requested the close.

Give each opened menu a monotonic open-generation token stored on the
menu state. Each context.close closure captures the token it was created
with, and closeContextMenu no-ops when the captured token is no longer
the active one, so a stale close from a superseded menu can no longer
dismiss the menu that replaced it.

Fixes #664
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 7, 2026 4:11am
pierre-docs-diffshub Ready Ready Preview Jul 7, 2026 4:11am
pierre-docs-trees Ready Ready Preview Jul 7, 2026 4:11am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Skipped Skipped Jul 7, 2026 4:11am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Trees mishandles sequential right clicks

1 participant