Fix async terminal.write() causing garbled dashboard output

The terminal.write() method from @xterm/headless is async - the data
isn't in the buffer yet when we call serializeAsHTML() immediately
after. This caused empty or partially rendered output in the browser.

Now using the callback form of terminal.write(data, callback) to wait
for the write to complete before serializing and broadcasting to SSE
clients. This ensures the terminal buffer is fully updated before we
generate HTML from it.
This commit is contained in:
Jared Miller 2026-01-31 11:06:37 -05:00
parent 9bc77292cd
commit 31340fe0a8
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -520,12 +520,12 @@ const server = Bun.serve<SessionData>({
return;
}
// Write to terminal emulator (handles all ANSI sequences)
termSession.terminal.write(msg.data);
// Store raw ANSI in database
appendOutput(sessionId, msg.data);
// Write to terminal emulator (handles all ANSI sequences)
// Use callback to wait for write completion before serializing
termSession.terminal.write(msg.data, () => {
// Serialize current terminal state as HTML
const html = serializeAsHTML(termSession);
@ -535,6 +535,7 @@ const server = Bun.serve<SessionData>({
session_id: sessionId,
data: html,
});
});
return;
}