fix(web): prevent duplicate terminal paste - #8457
Adamulek123 wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a small, localized terminal bug fix that consolidates existing paste paths to prevent duplicate PTY input during clipboard races. Focused regression tests cover the affected scenarios, with no schema, security, persistence, or deployment changes. You can add or adjust custom eligibility rules. Learn more. |
|
Note 🤖 GPT-5.6 Sol responding on behalf of Theo Closing this because current main already prevents the duplicate-paste orderings covered here. This patch now centralizes existing behavior, and its tests call the proposed helper instead of the current event paths. It also does not cover the remaining inverse ordering where the async clipboard read delivers before a later native paste event. There is no behavior left in this PR that should land. |
|
Not sure why but I'm struggling with CMD+V double pasting everywhere whether inside or outside tmux. It might be because safari again. |
What Changed
Centralized terminal paste delivery so every non-empty paste invalidates older clipboard reads before writing to the PTY. Added focused coverage for keyboard/context-menu races, native/shortcut races, and empty paste data.
Why
Terminal paste can arrive through an async clipboard read or a native paste event. Keeping token invalidation in one method prevents both paths from delivering the same clipboard content.
Validation
vp test run apps/web/src/terminal/ghostty/surface.test.ts(46 passed)surface.tsandsurface.test.tsvp run --filter @t3tools/web typecheckChecklist
Implemented with GPT-5.6 Codex in T3 Code.
Note
Low Risk
Focused change to web terminal input handling with new regression tests; no auth, data persistence, or broader API surface changes.
Overview
Centralizes Ghostty terminal paste delivery in a new
paste()method so native events, keyboard shortcut clipboard reads, and hostpasteFromClipboardall share one path to bracketed-paste encode and send data to the PTY.When a non-empty paste wins,
paste()bumpspasteShortcutToken, which invalidates slower async reads that still hold an older token—so context-menu vs keyboard and shortcut vs native races no longer double-send the same clipboard text. Emptypaste()calls are no-ops and do not bump the token, so an empty native paste still lets a pending shortcut read complete.Adds unit tests for those race scenarios using a lightweight surface stub.
Reviewed by Cursor Bugbot for commit 7e5f267. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix duplicate terminal paste by consolidating delivery in
GhosttyTerminalSurface.pastepaste(data)method toGhosttyTerminalSurfacethat handles token bumping, encoding, and delivery viaoptions.onData; early-returns on disposed surfaces or empty strings.onKeyDownclipboard read,onPasteevent handler, andpasteFromClipboard— throughthis.paste()instead of duplicating the token/dispatch logic inline.pasteFromClipboardnow callsonDatafor non-empty clipboard text even whencore.encodePastereturns an empty string; empty input remains a no-op.Macroscope summarized 7e5f267.