From 3d3c7ba372f39021eededb47a6d9371dc683dd34 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Sun, 12 Apr 2026 18:07:06 -0700 Subject: [PATCH] Fix live session bugs found during E2E testing Three bugs found and fixed during real end-to-end testing: 1. MutationObserver infinite loop: the observer watched all of document.body, so our own bar DOM updates triggered it, which rebuilt the bar, which triggered it again, freezing the page. Fix: filter mutations to only react when nodes with data-impeccable-variant attributes are added inside the variant wrapper. Added a re-entrancy guard as a safety net. 2. Premature exit on transient WS disconnect: the server fired an exit event the instant the last WebSocket client disconnected. HMR page reloads cause brief disconnects that triggered false exits. Fix: 8-second debounce before sending exit, cancelled if a client reconnects within that window. 3. WS auth_ok clobbering resumed session state: after a page reload, resumeSession() correctly set state to CYCLING, but then the async WS auth_ok handler overwrote it to PICKING. Fix: only transition to PICKING from IDLE, not from an active session state. Also fixed: highlight tracking during variant cycling (update selectedElement to the newly visible variant's content element so the highlight follows the active variant, not the hidden one). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/live/browser.js | 115 ++++++++++++++++++++++++++++++++++++-------- src/live/server.mjs | 15 +++++- 2 files changed, 108 insertions(+), 22 deletions(-) diff --git a/src/live/browser.js b/src/live/browser.js index a542af543..223bd36a0 100644 --- a/src/live/browser.js +++ b/src/live/browser.js @@ -13,16 +13,19 @@ 'use strict'; if (typeof window === 'undefined') return; + // Guard against double-init. Bun's HTML loader may process the