[trees] Fix sequential right-click closing the context menu (#664)#945
Draft
claude[bot] wants to merge 1 commit into
Draft
[trees] Fix sequential right-click closing the context menu (#664)#945claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DropdownMenuonOpenChange) fires itsclose()asynchronously — previously this closed whatever menu was open, which was now menu B. Eachcontext.closeclosure captures the token it was created with, andcloseContextMenuno-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 (openContextMenuForRowand the button-trigger path), guardedcloseContextMenuwith an optional expected token, and had thecontext.closeclosure 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
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.cd packages/trees && bun test test/file-tree-context-menu-sequential-right-click.test.tsexpect(slotted).not.toBeNull()receivesnull).cd packages/trees && bun test-> 325 pass / 0 fail across 29 files.tsc --noEmit -p packages/trees/tsconfig.json-> clean.Related issues
Fixes #664