fix(terminal): init payload never sent due to ws.onopen being overwritten
All checks were successful
Beta Release / beta (push) Successful in 40s

connectWebSocket set ws.onopen to send the shell init payload, but
initTerminal immediately overwrote it with a state-only handler.
Switched to addEventListener so both handlers coexist.
This commit is contained in:
Augustin
2026-04-22 20:05:10 +02:00
parent e0e1e73bca
commit 93a22d4075

View File

@@ -94,15 +94,15 @@ function connectWebSocket(term, fitAddon, initPayload) {
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
const ws = new WebSocket(`${proto}//${window.location.host}/api/ws/terminal`)
ws.onopen = () => {
ws.addEventListener('open', () => {
ws.send(JSON.stringify(initPayload))
const dims = fitAddon.proposeDimensions()
if (dims) {
ws.send(JSON.stringify({ type: 'resize', rows: dims.rows, cols: dims.cols }))
}
}
})
ws.onmessage = (event) => {
ws.addEventListener('message', (event) => {
try {
const msg = JSON.parse(event.data)
if (msg.type === 'output') {
@@ -113,15 +113,15 @@ function connectWebSocket(term, fitAddon, initPayload) {
} catch {
term.write(event.data)
}
}
})
ws.onclose = () => {
ws.addEventListener('close', () => {
term.write('\r\n\x1b[33m— Connection closed —\x1b[0m\r\n')
}
})
ws.onerror = () => {
ws.addEventListener('error', () => {
term.write('\r\n\x1b[31m— Connection error —\x1b[0m\r\n')
}
})
term.onData((data) => {
if (ws.readyState === WebSocket.OPEN) {