GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): terminal paste no longer reaches a restarted shell by fionn77 · Pull Request #44319 · pingdotgg/t3code

fix(web): terminal paste no longer reaches a restarted shell #44319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fionn77 wants to merge 4 commits into pingdotgg:main
base: main
Loading
Loading
from fionn77:fix/terminal-paste-restart
+58 −2
Open

fix(web): terminal paste no longer reaches a restarted shell #44319

Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
1db8c07
fix(web): terminal paste no longer reaches a restarted shell
fionn77 Nov 27, 2026
2f081fe
Merge remote-tracking branch 'origin/main' into fix/terminal-paste-re…
juliusmarminge Nov 27, 2026
cab0385
refactor(web): keep the WASM-loading comment on the listener it explains
juliusmarminge Nov 27, 2026
c74644d
fix(web): paste guard also catches a new terminal attach stream
fionn77 Nov 27, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 apps/web/src/components/ThreadTerminalDrawer.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ function TerminalSessionViewport({
? { text, ...(fallback === undefined ? {} : { fallback }) }
: null,
),
inputLifecycle: () => readTerminalSession().lifecycleVersion,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

// Surface listeners start before WASM loading finishes and the terminal handler exists.
onContextMenu: (event) => {
if (terminalRef.current) void showTerminalContextMenu(event);
Expand Down
27 changes: 27 additions & 0 deletions 27 apps/web/src/terminal/ghostty/surface.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,33 @@ describe("GhosttyTerminalSurface visibility", () => {
expect(harness.onData.mock.calls).toEqual([["echo hi"]]);
});

it.each(["shortcut", "menu"])(
"drops a %s paste whose shell restarts during the clipboard read",
async (source) => {
const harness = createHarness();
const { promise: read, resolve } = Promise.withResolvers<string>();
vi.stubGlobal("navigator", {
platform: "MacIntel",
clipboard: { readText: () => read },
});
let lifecycle = 1;
const surface = await harness.create({
beforeKey: () => true,
inputLifecycle: () => lifecycle,
});

const menuPaste =
source === "menu" ? surface.pasteFromClipboard(() => read) : Promise.resolve();
if (source === "shortcut") key(surface, "v", "KeyV", { metaKey: true });
lifecycle = 2;
resolve("rm -rf build");
await read;
await menuPaste;

expect(harness.onData).not.toHaveBeenCalled();
},
);

it.each(["V keyup", "blur", "Meta keyup without V keyup"])(
"accepts a later identical menu paste after %s",
async (end) => {
Expand Down
21 changes: 19 additions & 2 deletions 21 apps/web/src/terminal/ghostty/surface.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ export interface GhosttyTerminalSurfaceOptions {
readonly onLinkHover?: (text: string | null, fallbackText?: string) => void;
/** The host must prevent the default menu; native Paste cannot reach a canvas terminal. */
readonly onContextMenu?: (event: MouseEvent) => void;
/** Identifies the shell receiving input; a clipboard read that outlives it is dropped. */
readonly inputLifecycle?: () => unknown;
}

export class GhosttyTerminalSurface {
Expand Down Expand Up @@ -1031,8 +1033,16 @@ export class GhosttyTerminalSurface {
isCurrent: () => boolean = () => true,
): Promise<void> {
const token = ++this.pasteShortcutToken;
const lifecycle = this.options.inputLifecycle?.();
const text = await readText();
if (this.disposed || this.pasteShortcutToken !== token || !isCurrent()) return;
if (
this.disposed ||
this.pasteShortcutToken !== token ||
this.options.inputLifecycle?.() !== lifecycle ||
!isCurrent()
) {
return;
}
this.pasteShortcutToken += 1;
if (text.length === 0) return;
const encoded = this.core.encodePaste(text);
Expand Down Expand Up @@ -1247,9 +1257,16 @@ export class GhosttyTerminalSurface {
// Keep native paste available if the read is denied. The token drops
// a late read; the gesture drops a native duplicate when the read wins.
const token = ++this.pasteShortcutToken;
const lifecycle = this.options.inputLifecycle?.();
void clipboard.readText().then(
(text) => {
if (this.disposed || this.pasteShortcutToken !== token) return;
if (
this.disposed ||
this.pasteShortcutToken !== token ||
this.options.inputLifecycle?.() !== lifecycle
) {
return;
}
this.pasteShortcutToken += 1;
if (text.length === 0) return;
if (this.pasteShortcutGesture === gesture) gesture.readText = text;
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.