mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 06:06:37 +03:00
The reload-only fix missed the primary case: Bun's HTML loader hot-patches the DOM in place rather than doing a full page load, so the resume codepath never ran and the browser's scroll drifted wherever Bun's patch left it. Likewise variant cycling (taller → shorter) and agent-driven variant inserts both mutate layout without a reload. Add a scroll lock: on Go (and on resume after a true reload), capture the selected element's viewport-top and install a MutationObserver on body that re-measures the target and corrects scroll on every batch of DOM mutations. The target is re-resolved each pass via sessionId + visible variant, so it survives DOM swaps that invalidate `selectedElement`. Scroll intent events (wheel, touchstart, arrow/page keys) re-anchor to the new position so we never fight a user who scrolls during a session. Also set `scrollRestoration = 'manual'` at init so true reloads don't land the user somewhere odd before our correction runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>