diff options
| author | adamelmore <[email protected]> | 2026-01-27 07:32:36 -0600 |
|---|---|---|
| committer | adamelmore <[email protected]> | 2026-01-27 08:43:36 -0600 |
| commit | 27bb82761bee83ce20716b24d6f0e246bec4bcf3 (patch) | |
| tree | 7b644d5a69feb3671fb1d19c971e86b89fc4db59 /packages/app/src/components/terminal.tsx | |
| parent | c7e2f1965dbb1d3dd2c9f0a645874b5ed4b2fcaf (diff) | |
| download | opencode-27bb82761bee83ce20716b24d6f0e246bec4bcf3.tar.gz opencode-27bb82761bee83ce20716b24d6f0e246bec4bcf3.zip | |
perf(app): shared terminal ghostty-web instance
Diffstat (limited to 'packages/app/src/components/terminal.tsx')
| -rw-r--r-- | packages/app/src/components/terminal.tsx | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/app/src/components/terminal.tsx b/packages/app/src/components/terminal.tsx index 78c33baff..022369afe 100644 --- a/packages/app/src/components/terminal.tsx +++ b/packages/app/src/components/terminal.tsx @@ -16,6 +16,19 @@ export interface TerminalProps extends ComponentProps<"div"> { onConnectError?: (error: unknown) => void } +let shared: Promise<{ mod: typeof import("ghostty-web"); ghostty: Ghostty }> | undefined + +const loadGhostty = () => { + if (shared) return shared + shared = import("ghostty-web") + .then(async (mod) => ({ mod, ghostty: await mod.Ghostty.load() })) + .catch((err) => { + shared = undefined + throw err + }) + return shared +} + type TerminalColors = { background: string foreground: string @@ -53,7 +66,6 @@ export const Terminal = (props: TerminalProps) => { let handleResize: () => void let handleTextareaFocus: () => void let handleTextareaBlur: () => void - let reconnect: number | undefined let disposed = false const getTerminalColors = (): TerminalColors => { @@ -112,8 +124,11 @@ export const Terminal = (props: TerminalProps) => { onMount(() => { const run = async () => { - const mod = await import("ghostty-web") - ghostty = await mod.Ghostty.load() + const loaded = await loadGhostty() + if (disposed) return + + const mod = loaded.mod + ghostty = loaded.ghostty const once = { value: false } |
