perf(app): shared terminal ghostty-web instance

This commit is contained in:
adamelmore
2026-01-27 07:32:36 -06:00
parent c7e2f1965d
commit 27bb82761b

View File

@@ -16,6 +16,19 @@ export interface TerminalProps extends ComponentProps<"div"> {
onConnectError?: (error: unknown) => void 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 = { type TerminalColors = {
background: string background: string
foreground: string foreground: string
@@ -53,7 +66,6 @@ export const Terminal = (props: TerminalProps) => {
let handleResize: () => void let handleResize: () => void
let handleTextareaFocus: () => void let handleTextareaFocus: () => void
let handleTextareaBlur: () => void let handleTextareaBlur: () => void
let reconnect: number | undefined
let disposed = false let disposed = false
const getTerminalColors = (): TerminalColors => { const getTerminalColors = (): TerminalColors => {
@@ -112,8 +124,11 @@ export const Terminal = (props: TerminalProps) => {
onMount(() => { onMount(() => {
const run = async () => { const run = async () => {
const mod = await import("ghostty-web") const loaded = await loadGhostty()
ghostty = await mod.Ghostty.load() if (disposed) return
const mod = loaded.mod
ghostty = loaded.ghostty
const once = { value: false } const once = { value: false }