From f4f9157f8d5e1000915a8b82ef619e1d3a71a794 Mon Sep 17 00:00:00 2001 From: webtecnica Date: Wed, 29 Jul 2026 21:53:33 -0300 Subject: [PATCH] fix: guard _autoScrollFollow access against ReferenceError before settings init Browser race in static/ui.js: _autoScrollFollow can be undefined when scroll/scrollpin listeners fire before boot.js initializes settings. Bare global reference (ReferenceError) occurs on the golden path. Fix: wrap both consumer sites with a typeof guard that defaults to true (matching the boot.js fallback) when the variable hasn't been set. Closes #6606 --- static/ui.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/ui.js b/static/ui.js index 3b51b5a4..3be12f7c 100644 --- a/static/ui.js +++ b/static/ui.js @@ -6104,7 +6104,7 @@ if(typeof window!=='undefined'){ if(nearBottom){ _nearBottomCount=_nearBottomCount+1; if(_nearBottomCount>=2){_scrollPinned=true;_nearBottomCount=0;} - }else if(!movedUp && _autoScrollFollow && _scrollPinned){ + }else if(!movedUp && (typeof _autoScrollFollow==='undefined'||_autoScrollFollow) && _scrollPinned){ // Content-grew-beneath-a-pinned-viewport case (NOT a user scroll-away). // During streaming on a tall transcript (esp. mobile, where chunks land // fast), new content increases scrollHeight under a stationary viewport, @@ -6779,7 +6779,7 @@ function _shouldFollowMessagesOnDomReplace(){ // following only for users who are still pinned or effectively at the tail. // A broad near-bottom window causes long answers/mobile readers who scroll up // a little to read mid-stream to get snapped back to the bottom on completion. - return _autoScrollFollow && !_messageUserUnpinned && (_scrollPinned || _isMessagePaneNearBottom(120)); + return (typeof _autoScrollFollow==='undefined'||_autoScrollFollow) && !_messageUserUnpinned && (_scrollPinned || _isMessagePaneNearBottom(120)); } function _followMessagesAfterDomReplace(){ if(_shouldFollowMessagesOnDomReplace()){