diff --git a/static/sessions.js b/static/sessions.js index 849ee30c..183342ef 100644 --- a/static/sessions.js +++ b/static/sessions.js @@ -392,6 +392,12 @@ async function loadSession(sid){ S.session=data.session; S.session._modelResolutionDeferred=true; S.lastUsage={...(data.session.last_usage||{})}; + // Reset scroll-direction tracker on session switch so the new chat's + // first scroll doesn't compare against the previous chat's scrollTop + // and false-trigger an unpin (#1731 follow-up — Opus stage-302 SHOULD-FIX). + if (typeof window !== 'undefined' && typeof window._resetScrollDirectionTracker === 'function') { + try { window._resetScrollDirectionTracker(); } catch (_) {} + } // Sync workspace display immediately so the chip label reflects the new session's workspace // before any async message-loading begins (mirrors how model is handled). if(typeof syncTopbar==='function') syncTopbar(); diff --git a/static/ui.js b/static/ui.js index 2e226515..bef64a22 100644 --- a/static/ui.js +++ b/static/ui.js @@ -1401,6 +1401,11 @@ let _scrollPinned=true; let _programmaticScroll=false; let _nearBottomCount=0; let _lastScrollTop=null; +// Reset hook for session-switch — called from sessions.js loadSession() to +// prevent the new chat's first scroll comparing against the previous chat's +// scrollTop (Opus stage-302 SHOULD-FIX, #1731 follow-up). +function _resetScrollDirectionTracker(){ _lastScrollTop=null; } +if (typeof window !== 'undefined') window._resetScrollDirectionTracker = _resetScrollDirectionTracker; (function(){ const el=document.getElementById('messages'); if(!el) return;