Skip to content

[trees] Keep context menu closable when the same row reopens it - #1188

Merged
SlexAxton merged 1 commit into
mainfrom
fix/trees-context-menu-reopen-close-token
Oct 13, 2026
Merged

SlexAxton merged 1 commit into
mainfrom
fix/trees-context-menu-reopen-close-token

Conversation

@claude

@claude claude Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Requested by Alex Sexton · Slack thread

Description

Before: If you right-click a row whose context menu is already open, the menu stays on screen, but its close() stops working. Consumer actions such as Radix onOpenChange(false) cannot close it. Only Escape or an outside click closes it. Also, type-aware oxlint fails on main after #945, so the "Build, test, lint" check is red.

After: A second right-click on the same row keeps the menu open, and that menu's close() still closes it. The lint check on main passes again.

How: Each open issued a new token. But the slot effect is keyed on path::source, so for the same row it keeps the old menu and its old close(), which carries the old token. closeContextMenu then rejected that close() as stale. The new nextContextMenuToken() helper in FileTreeView.tsx reuses the open menu's token when the path and source match. It issues a new token in all other cases. The row path and the trigger-button path both use it. I did not add the token to the effect key, because that re-runs render() and replaces the menu DOM (see the comment above activeContextMenuKey). In the #945 test, return menu as unknown as HTMLElement; is now return menu;. This fixes the typescript(no-unnecessary-type-assertion) error that makes main red.

Motivation & Context

This is a follow-up to #945 (#945). It fixes the valid post-merge Codex review comment (#945 (comment)). It also fixes the red lint on main (merge commit 14c110c).

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

Checklist

  • I have read the
    contributing guidelines
  • My code follows the code style of the project (moon run root:lint)
  • My code is formatted properly (moon run root:format)
  • I have updated the documentation accordingly (if applicable)
  • I have added tests to cover my changes (if applicable)
  • All new and existing tests pass (moonx diffs:test)

Verification (moon could not load its toolchain plugin in this sandbox, so I ran the task commands directly):

  • bun test in packages/trees: 329 pass, 0 fail. The new test fails without the fix and passes with it.
  • tsc --noEmit --pretty in packages/trees: pass.
  • oxlint --type-aware --tsconfig tsconfig.oxlint.json packages: pass.
  • oxfmt --check on the changed files: pass.

How was AI used in generating this PR

Claude Code found the cause, wrote the fix and the regression test, and ran the checks above. A human should review it.

Related issues

🤖 Generated with Claude Code

https://claude.ai/code/session_01S8sCGahM5K2sY4efY2hWUM


Generated by Claude Code

Right-clicking the row whose menu is already open (same path and source)
keeps the same slot menu and its close() closure, but each open issued a
new token. closeContextMenu then rejected that menu's close() as stale, so
consumer actions such as Radix onOpenChange(false) could not close it.

Add nextContextMenuToken(), which reuses the open menu's token when the
path and source match and issues a new token otherwise. Use it for the
row and trigger-button open paths. Add a regression test that
right-clicks the same row twice and closes the menu with its close().

Also remove an unnecessary type assertion in the #945 test that fails
type-aware oxlint on main.

Follow-up to #945.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S8sCGahM5K2sY4efY2hWUM
@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
pierre-diffshub Ready Ready Preview Oct 13, 2026 2:08pm UTC
pierre-docs-diffs Ready Ready Preview Oct 13, 2026 2:08pm UTC
pierre-docs-trees Ready Ready Preview Oct 13, 2026 2:08pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
pierrejs-diff-demo Skipped Skipped Oct 13, 2026 2:08pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T14:31:52.786789Z e1eb2a0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SlexAxton
SlexAxton merged commit 3c763dc into main Oct 13, 2026
8 checks passed
@SlexAxton
SlexAxton deleted the fix/trees-context-menu-reopen-close-token branch October 13, 2026 14:32

This branch was successfully deployed

3 active and 1 inactive deployments
Preview – pierre-docs-trees — e1eb2a0d Deployed Oct 13, 2026 by vercel[bot]
Preview – pierre-docs-diffs — e1eb2a0d Deployed Oct 13, 2026 by vercel[bot]
Preview – pierre-diffshub — e1eb2a0d Deployed Oct 13, 2026 by vercel[bot]
Preview – pierrejs-diff-demo — e1eb2a0d Deployed Oct 13, 2026 by vercel[bot]
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.

2 participants