feat: enhance terminal functionality with debouncing and resize validation

- Implemented debouncing for terminal tab creation to prevent rapid requests.
- Improved terminal resizing logic with validation for minimum dimensions and deduplication of resize messages.
- Updated terminal panel to handle focus and cleanup more efficiently, preventing memory leaks.
- Enhanced initial connection handling to ensure scrollback data is sent before subscribing to terminal data.
This commit is contained in:
SuperComboGamer
2025-12-14 13:48:26 -05:00
parent 589155fa1c
commit 480589510e
3 changed files with 122 additions and 42 deletions

View File

@@ -305,6 +305,15 @@ export function TerminalView() {
// Create terminal in new tab
const createTerminalInNewTab = async () => {
// Debounce: prevent rapid terminal creation
const now = Date.now();
if (now - lastCreateTimeRef.current < CREATE_COOLDOWN_MS || isCreatingRef.current) {
console.log("[Terminal] Debounced terminal tab creation");
return;
}
lastCreateTimeRef.current = now;
isCreatingRef.current = true;
const tabId = addTerminalTab();
try {
const headers: Record<string, string> = {
@@ -332,6 +341,8 @@ export function TerminalView() {
}
} catch (err) {
console.error("[Terminal] Create session error:", err);
} finally {
isCreatingRef.current = false;
}
};
@@ -465,7 +476,7 @@ export function TerminalView() {
}
/>
)}
<Panel defaultSize={panelSize} minSize={15}>
<Panel defaultSize={panelSize} minSize={25}>
{renderPanelContent(panel)}
</Panel>
</React.Fragment>