[Bug]: Right panel launcher letters go into the composer when you open the panel after the page loads #21541
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/web
Steps to reproduce#
- Run the app from main with
vp run devand open the pairing URL it prints in Chrome. - Add a project for any local folder and start a new thread, so the composer is empty. Close the right panel if it is open, then reload the page and wait for it to finish loading.
- Click the Toggle right panel button at the top right. The empty Open a surface launcher appears, with T next to Terminal. Do not click the composer.
- Press T.
- Clear the composer. With the launcher still open, reload the page, wait for it to finish loading, and press T again.
Expected behavior#
T opens Terminal in step 4, as it does in step 5, and nothing goes into the composer.
Actual behavior#
In step 4, t lands in the composer, the launcher stays open and no terminal opens. In step 5, Terminal 1 opens and the composer stays empty.
Step 4 failed 4 of 4 times, each after a fresh reload with the panel closed. In step 4 and in step 5 the launcher's Open a surface element had focus before the press, because the launcher takes focus when it mounts. Focus does not explain the difference. Step 4 also failed once with focus on the page body, after a click on an empty part of the chat view. Closing the last terminal hides the whole right panel. Reopening it with the toolbar button and pressing T without a reload put t in the composer again.
Browser automation sent each press as a trusted key event. Nobody typed them by hand. Each recorded keydown had key t, code KeyT and isTrusted true. I pressed only T. Every launcher letter goes through the same listeners, so I expect the others to fail the same way, but I did not try them.
The cause is listener order. Type-to-focus in useChatShortcuts and the launcher in RightPanelEmptyState both add a capture keydown listener on window. Listeners on one target run in the order they were added. Type-to-focus adds its listener once, when the chat view mounts. The launcher adds its listener when it mounts. If the panel opens later, type-to-focus runs first. It types the letter into the composer and calls preventDefault, and the launcher's matcher then returns null for a prevented event. After a reload with the panel open, both mount in one commit. React runs the launcher's effect first because the launcher sits inside the chat view, so T opens Terminal. I worked this out from the code and did not instrument listener order in the app.
Type-to-focus used to leave launcher letters alone by reading data-surface-launcher-keys. #2829 removed that check, and the launcher still renders the attribute with nothing reading it. Since #20393 the hook adds the type-to-focus listener once, with [] deps. Before that, the same handler lived in an effect in ChatView that removed and re-added the listener whenever one of its 49 dependencies changed. I did not run code from before #20393, so I can't say which change first made this show up in the app. One possible fix is for type-to-focus to skip the letters an open launcher claims, as it did before #2829.
This is a different cause from the closed menu in #13403 and #18602, since T opens Terminal on the same draft after a reload. #21508 links here because a reviewer who tests that PR by opening the panel and pressing a letter will hit this first.
Impact#
Minor bug or occasional failure
Version or commit#
main @ f36dadb78
Environment#
macOS 27.2, Chrome 155.0.8059.80, web app from vp run dev
Logs or stack traces#
No response
Screenshots, recordings, or supporting files#
Step 4, the panel opened with its button, then T
Step 5, a reload with the launcher open, then T
Workaround#
Click the row in the launcher. Reloading with the panel open also makes the letters work, but they stopped again after I closed the last terminal and reopened the panel.
juliusmarminge added labelsaccepted
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Confirmed on current main, so this is accepted as a bug.
Type-to-focus and the launcher both listen for keydown on window in the capture phase. Type-to-focus attaches once when the chat view mounts (useChatShortcuts.ts:45-105). The launcher attaches when it mounts (RightPanelTabs.tsx:403-407). When the panel opens after page load, type-to-focus runs first. It types the letter into the composer and calls preventDefault (useChatShortcuts.ts:63-71). The launcher then ignores the prevented event (RightPanelTabs.tsx:253).
Nothing in the type-to-focus check (composerFocusRedirect.ts:51-69) skips launcher letters. The skip that read data-surface-launcher-keys was dropped in #2829, and the launcher still sets that attribute (RightPanelTabs.tsx:453) with nothing reading it.
This is separate from #13403 and #18602 (a closed menu staying mounted) and from #21508 (non-Latin layouts). Neither open PR touches type-to-focus. For now, clicking the launcher row still opens the surface.