From b0c1d0ab8ddac6ec67c0a4cf9a3aa0a85e290dbd Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Thu, 2 Apr 2026 04:46:50 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20remoteId=3D0=20treated=20as=20falsy=20?= =?UTF-8?q?=E2=80=94=20use=20null=20checks=20instead=20of=20||=20for=20int?= =?UTF-8?q?eger=20remoteId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remoteId is an integer index (0, 1, 2...) returned by /api/federation/sessions. In JavaScript, 0 is falsy, so all || '' patterns converted remoteId=0 to '' — making the first remote device (ALIENWARE, index 0) appear as a local session. The symptom: clicking an ALIENWARE session from spark-1 or spark-2 sent POST /api/sessions/{name}/connect ← local endpoint, session doesn't exist → 404 instead of POST /api/federation/0/connect/{name} ← correct federation proxy route Only affected the FIRST remote (index 0). spark-1 ↔ spark-2 worked because each sees the other as remoteId=1. Locations fixed in frontend/app.js: 1. buildTileHTML: session.remoteId ? → session.remoteId != null ? 2. buildSidebarHTML: session.remoteId || '' → session.remoteId != null ? ... : '' 3. _previewClickHandler: session && session.remoteId || '' → null-safe ternary 4. openSession _viewingRemoteId: opts.remoteId || '' → null-safe ternary 5. openSession _remoteId: opts.remoteId || '' → null-safe ternary 6. openSession routing: if (_remoteId) → if (_remoteId !== '') 7. closeSession DELETE guard: if (!_viewingRemoteId) → if (_viewingRemoteId === '') DOM dataset reads (tile.dataset.remoteId, item.dataset.remoteId) are unaffected because dataset values are always strings — '0' is truthy, so || '' worked there. Tests added: 5 new tests covering all four code paths (buildTileHTML, buildSidebarHTML, openSession connect routing, closeSession DELETE skip) with integer remoteId=0. Total: 291 → 296 tests, 0 failures. --- muxplex/frontend/app.js | 14 ++-- muxplex/frontend/tests/test_app.mjs | 114 ++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 7 deletions(-) diff --git a/muxplex/frontend/app.js b/muxplex/frontend/app.js index a6fb0bf..0ff0d1d 100644 --- a/muxplex/frontend/app.js +++ b/muxplex/frontend/app.js @@ -434,7 +434,7 @@ function buildTileHTML(session, index, mobile) { } const lastLines = allLines.slice(_lineCount).join('\n'); - const remoteIdAttr = session.remoteId ? ` data-remote-id="${escapeHtml(session.remoteId)}"` : ''; + const remoteIdAttr = session.remoteId != null ? ` data-remote-id="${escapeHtml(session.remoteId)}"` : ''; return ( `
` + `
` + @@ -489,7 +489,7 @@ function buildSidebarHTML(session, currentSession) { const lastLines = allLines.slice(-20).join('\n'); return ( - `
` + + `
` + `