From 631d62d9e89f79d8ac48df06b1010474d2143f2a Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Tue, 23 Jun 2026 03:11:06 -0400 Subject: [PATCH] fix(scroll): keep shared anchor restore semantics after rebase (#4346) --- static/ui.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/static/ui.js b/static/ui.js index 9a83386d..02bbb939 100644 --- a/static/ui.js +++ b/static/ui.js @@ -822,7 +822,8 @@ function _restoreMessageViewportAnchor(anchor, rawIdxDelta){ const targetTop=Number(anchor.topOffset)||0; _programmaticScroll=true;_programmaticScrollSetAt=performance.now(); container.scrollTop+=(rect.top-containerRect.top)-targetTop; - _deferClearProgrammaticScroll(); + if(typeof _deferClearProgrammaticScroll==='function') _deferClearProgrammaticScroll(); + else requestAnimationFrame(()=>{ setTimeout(()=>{ _programmaticScroll=false; },0); }); return true; } let _messageViewportAnchorRemounting=false; @@ -10921,7 +10922,8 @@ function _restoreMessageScrollSnapshot(snapshot){ } } if(!restoredViaAnchor){ - _deferClearProgrammaticScroll(); + if(typeof _deferClearProgrammaticScroll==='function') _deferClearProgrammaticScroll(); + else requestAnimationFrame(()=>{ setTimeout(()=>{ _programmaticScroll=false; },0); }); } } function _restoreMessageScrollSnapshotSameFrame(snapshot){ @@ -10935,23 +10937,6 @@ function _restoreMessageScrollSnapshotSameFrame(snapshot){ ? _restoreMessageViewportAnchor(snapshot.anchor,0) : false; } - if(!restoredViaAnchor&&snapshot.anchor&&snapshot.anchor.rawIdx!=null&& - !el.querySelector(`[data-msg-idx="${snapshot.anchor.rawIdx}"]`)&& - typeof _getVisibleMessagesWithIdx==='function'&& - typeof _messageVisibleIndexForRawIdx==='function'&& - typeof _messageVirtualScrollTopForVisibleIdx==='function'){ - const visWithIdx=_getVisibleMessagesWithIdx(); - const visIdx=_messageVisibleIndexForRawIdx(snapshot.anchor.rawIdx,visWithIdx); - if(visIdx>=0){ - _programmaticScroll=true;_programmaticScrollSetAt=performance.now(); - el.scrollTop=_messageVirtualScrollTopForVisibleIdx(visWithIdx,visIdx,el); - _messageVirtualWindowKey=''; - renderMessages({preserveScroll:true}); - restoredViaAnchor=(typeof _restoreMessageViewportAnchor==='function') - ? _restoreMessageViewportAnchor(snapshot.anchor,0) - : false; - } - } if(!restoredViaAnchor){ const maxTop=Math.max(0,el.scrollHeight-el.clientHeight); const bottom=Number(snapshot.bottom); @@ -10972,7 +10957,8 @@ function _restoreMessageScrollSnapshotSameFrame(snapshot){ _nearBottomCount=0; } if(!restoredViaAnchor){ - _deferClearProgrammaticScroll(); + if(typeof _deferClearProgrammaticScroll==='function') _deferClearProgrammaticScroll(); + else requestAnimationFrame(()=>{ setTimeout(()=>{ _programmaticScroll=false; },0); }); } } function _renderMessagesWithScrollSnapshot(options){