fix(app): terminal issues (#14329)

This commit is contained in:
Adam
2026-02-19 14:54:09 -06:00
committed by GitHub
parent 40a939f5f0
commit f8dad0ae17
3 changed files with 81 additions and 48 deletions

View File

@@ -18,12 +18,14 @@ export namespace Pty {
type Socket = {
readyState: number
data?: unknown
send: (data: string | Uint8Array | ArrayBuffer) => void
close: (code?: number, reason?: string) => void
}
type Subscriber = {
id: number
token: unknown
}
const sockets = new WeakMap<object, number>()
@@ -37,6 +39,19 @@ export namespace Pty {
return next
}
const token = (ws: Socket) => {
const data = ws.data
if (!data || typeof data !== "object") return
const events = (data as { events?: unknown }).events
if (events && typeof events === "object") return events
const url = (data as { url?: unknown }).url
if (url && typeof url === "object") return url
return data
}
// WebSocket control frame: 0x00 + UTF-8 JSON.
const meta = (cursor: number) => {
const json = JSON.stringify({ cursor })
@@ -194,6 +209,12 @@ export namespace Pty {
session.subscribers.delete(ws)
continue
}
if (sub.token !== undefined && token(ws) !== sub.token) {
session.subscribers.delete(ws)
continue
}
try {
ws.send(chunk)
} catch {
@@ -291,7 +312,7 @@ export namespace Pty {
}
owners.set(ws, id)
session.subscribers.set(ws, { id: socketId })
session.subscribers.set(ws, { id: socketId, token: token(ws) })
const cleanup = () => {
session.subscribers.delete(ws)