mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
2ceac319b8
## Problem The **Open in Cursor** and **Open in VS Code** buttons on the agent detail page were broken. Clicking them did nothing. ### Root Cause The `handleOpenInEditor` handler in `AgentDetail.tsx` called `window.location.assign()` with a custom protocol URI (`vscode://` or `cursor://`) **after** an `await API.getApiKey()` call. This creates an async boundary that breaks the browser's user gesture chain, causing custom protocol navigations (`vscode://`, `cursor://`) to be silently blocked by the browser. The handler was invoked from a Radix `DropdownMenuItem.onSelect`, which adds another layer of event indirection that makes the gesture chain more fragile. In contrast, the workspace page's `VSCodeDesktopButton` works because it uses a direct `onClick` handler on a button element. ## Fix - **Eagerly fetch and cache the API key** via `useQuery` when workspace and agent data is available - **Make `handleOpenInEditor` synchronous** — it reads the cached key instead of awaiting a network call, keeping `window.location.assign()` within the original user gesture context - **Disable buttons** while the API key is still loading (`canOpenEditors` now gates on key availability) - **Simplify** the `onOpenInEditor` callback (remove `void` async wrapper)