Skip to content

fix(composer): refresh @ mention picker on workspace/project switch (#3601)#3606

Merged
esengine merged 1 commit into
esengine:main-v2from
SuMuxi66:fix/mention-picker-workspace-refresh
Jun 9, 2026
Merged

fix(composer): refresh @ mention picker on workspace/project switch (#3601)#3606
esengine merged 1 commit into
esengine:main-v2from
SuMuxi66:fix/mention-picker-workspace-refresh

Conversation

@SuMuxi66

@SuMuxi66 SuMuxi66 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3601 — @ mention picker not refreshing when switching between projects.

Problem

When switching from project A to project B, the @ mention picker still showed project A's file candidates because:

  1. dirCache/searchCache keys didn't include workspace context — switching projects hit stale cache entries
  2. ListDir/SearchFileRefs effect dependencies didn't include cwd — no re-fetch on workspace switch
  3. openPastChats had no race condition protection — stale async responses could overwrite new workspace state

Reproduction

  1. Open project A, type @ → see A's files
  2. Switch to project B, type @Bug: still shows A's files
  3. Expected: shows B's files only

Changes (1 file: Composer.tsx)

  • cwdRef snapshot pattern: Detect workspace switches in async openPastChats, discard stale ListSessions responses
  • useEffect([cwd]): Invalidate all @ mention state (caches, entries, past chats, loading, active index) when cwd changes
  • prevCwdRef: Skip the effect on initial mount, avoiding unnecessary re-renders
  • Add cwd to effect deps: ListDir and SearchFileRefs effects re-fetch when workspace changes while menu is open
  • Conditional finally: Only reset loadingPastChats when cwd hasn't changed, preventing stale async from overwriting new state

Verification

  • A project: @ shows A-only files
  • Switch to B project: @ shows B-only files, no A files
  • @ open while switching: candidates auto-refresh to new project
  • @past:chats entry still present and functional
  • TypeScript compilation passes
  • Security review: no vulnerabilities found (change is security-enhancing)
  • Code review: 2 minor issues found and fixed (mount re-render, effect optimization)

Security Review

No exploitable issues found. The change is security-enhancing — prevents cross-project data leakage by invalidating caches on workspace switch.

…sengine#3601)

When switching between projects, the @ mention picker retained stale
candidates from the previous project because dirCache/searchCache keys
did not include workspace context and the ListDir/SearchFileRefs effects
did not depend on cwd.

Changes:
- Add cwdRef snapshot pattern to detect workspace switches in async
  openPastChats callback, discarding stale ListSessions responses
- Add useEffect([cwd]) to invalidate all @ mention state (caches,
  entries, past chats, loading, active index) when cwd changes
- Use prevCwdRef to skip the effect on initial mount, avoiding
  unnecessary re-renders with empty-array references
- Add cwd to ListDir and SearchFileRefs effect dependencies so the
  picker re-fetches when the workspace changes while the menu is open
- Conditionally reset loadingPastChats in openPastChats finally block
  to prevent stale async responses from overwriting new workspace state

Closes esengine#3601
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) and removed v2 Go rewrite (1.x) — main-v2 branch, active development labels Jun 8, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff: the fix is correct, focused, and CI is green. Approving for merge.

@esengine esengine merged commit 3141ddd into esengine:main-v2 Jun 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @功能刷新有问题

2 participants