Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(bridge): show reconnect overlay on initial-connect failure (no blank screen)

enesfcf713a3dbd0
diff --git a/src/renderer/bridge/ws-bridge-overlay.test.ts b/src/renderer/bridge/ws-bridge-overlay.test.ts
new file mode 100644
index 000000000..b940d45e1
--- /dev/null
+++ b/src/renderer/bridge/ws-bridge-overlay.test.ts
@@ -0,0 +1,80 @@
+// The reconnect overlay must show on an initial-connect failure (server down at page load), not
+// just on a later drop. These tests exercise the exported overlay helpers directly.
+//
+// NOTE: the vitest suite here runs in the `node` environment (no jsdom/happy-dom is installed in
+// this repo), so we mount a tiny in-memory DOM stub covering exactly the surface the overlay code
+// touches (createElement / setAttribute / style.cssText / getElementById / body.appendChild /
+// querySelector). This keeps the test hermetic without adding a DOM dependency.
+import { describe, it, expect, beforeEach, afterEach } from 'vitest'
+import { showReconnectOverlay, isOverlayMounted } from './ws-bridge'
+
+interface StubEl {
+ id: string
+ textContent: string
+ style: { cssText: string; position: string }
+ attrs: Record<string, string>
+ setAttribute(name: string, value: string): void
+ getAttribute(name: string): string | null
+}
+
+function makeEl(): StubEl {
+ const el: StubEl = {
+ id: '',
+ textContent: '',
+ style: {
+ cssText: '',
+ get position(): string {
+ const m = /(?:^|;)position:([^;]+)/.exec(el.style.cssText)
+ return m ? m[1].trim() : ''
+ }
+ } as StubEl['style'],
+ attrs: {},
+ setAttribute(name, value) {
+ this.attrs[name] = value
+ },
+ getAttribute(name) {
+ return name in this.attrs ? this.attrs[name] : null
+ }
+ }
+ return el
+}
+
+let children: StubEl[]
+
+beforeEach(() => {
+ children = []
+ ;(globalThis as Record<string, unknown>).document = {
+ createElement: () => makeEl(),
+ getElementById: (id: string) => children.find((c) => c.id === id) ?? null,
+ body: { appendChild: (el: StubEl) => children.push(el) },
+ querySelector: (sel: string) => {
+ const attr = /^\[([^\]]+)\]$/.exec(sel)?.[1]
+ if (!attr) return null
+ return children.find((c) => c.getAttribute(attr) !== null) ?? null
+ }
+ }
+})
+
+afterEach(() => {
+ delete (globalThis as Record<string, unknown>).document
+})
+
+describe('reconnect overlay', () => {
+ it('mounts a fixed full-screen overlay with the reconnect message', () => {
+ expect(isOverlayMounted()).toBe(false)
+ showReconnectOverlay()
+ expect(isOverlayMounted()).toBe(true)
+ const el = (globalThis.document as unknown as { querySelector(s: string): StubEl | null }).querySelector(
+ '[data-nt-reconnect]'
+ )
+ expect(el).toBeTruthy()
+ expect(el!.style.position).toBe('fixed')
+ expect(el!.textContent).toMatch(/bağlan/i)
+ })
+
+ it('is idempotent — a second call does not mount a duplicate', () => {
+ showReconnectOverlay()
+ showReconnectOverlay()
+ expect(children.filter((c) => c.getAttribute('data-nt-reconnect') !== null).length).toBe(1)
+ })
+})
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index 03aac6317..bedf28e6d 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -317,10 +317,18 @@ function wsUrl(): string {
// ── Reconnect overlay (kept out of RpcClient's unit-tested core) ────────────────────────────
const OVERLAY_ID = 'nt-reconnect-overlay'
-function showReconnectOverlay(): void {
+/** Is the reconnect overlay currently mounted? Exported for the unit test. */
+export function isOverlayMounted(): boolean {
+ return typeof document !== 'undefined' && document.getElementById(OVERLAY_ID) !== null
+}
+
+/** Mount the full-screen "reconnecting" overlay (idempotent). Exported so both the initial-connect
+ * failure path and the later onClose path — and the unit test — mount the identical UI. */
+export function showReconnectOverlay(): void {
if (typeof document === 'undefined' || document.getElementById(OVERLAY_ID)) return
const el = document.createElement('div')
el.id = OVERLAY_ID
+ el.setAttribute('data-nt-reconnect', '')
el.style.cssText =
'position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;' +
'justify-content:center;background:rgba(0,0,0,0.72);color:#fff;' +
@@ -389,7 +397,16 @@ function startReconnect(): void {
*/
export async function installWsBridge(): Promise<void> {
const client = new RpcClient(wsUrl())
- await client.ready()
+ try {
+ await client.ready()
+ } catch {
+ // First connection failed (server down at page load, or the socket errored before opening).
+ // Show the SAME reconnect overlay + backoff loop as a later drop instead of rejecting — a
+ // rejection here would bubble out of bootstrap() and leave a blank screen. `startReconnect`
+ // reloads the page on the first successful reopen, which re-runs installWsBridge cleanly.
+ startReconnect()
+ return
+ }
client.onClose(() => startReconnect())
const api: NodeTerminalApi = {
...buildStubApi(),