fix(FN-912): move scrollback buffer reset to WebSocket onopen handler
Move initialBufferRef reset from the beginning of connect() to inside ws.onopen to ensure the buffer is fresh only when the new connection is established. This prevents a race condition where the buffer could be cleared before the WebSocket is ready, causing scrollback data to be lost when terminal tabs are switched.
This commit is contained in:
@@ -192,8 +192,6 @@ export function useTerminal(sessionId: string | null): UseTerminalReturn {
|
||||
}
|
||||
|
||||
isManualCloseRef.current = false;
|
||||
// Reset buffer for new connection — previous session's data is stale
|
||||
initialBufferRef.current = createEmptyBuffer();
|
||||
setConnectionStatus("connecting");
|
||||
|
||||
// Build WebSocket URL
|
||||
@@ -204,6 +202,10 @@ export function useTerminal(sessionId: string | null): UseTerminalReturn {
|
||||
wsRef.current = ws;
|
||||
|
||||
ws.onopen = () => {
|
||||
// Reset buffer ONLY when connection is established — ensures any
|
||||
// late-arriving messages from a previous session are discarded and
|
||||
// the new session's scrollback/data is captured in a fresh buffer.
|
||||
initialBufferRef.current = createEmptyBuffer();
|
||||
setConnectionStatus("connected");
|
||||
reconnectAttemptsRef.current = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user