@@ -58,6 +58,7 @@ export function LogView({ logs, isRunning, onClearLogs }: LogViewProps) {
5858 const [ viewMode , setViewMode ] = useState < "pretty" | "raw" > ( "pretty" ) ;
5959 const [ highlightedIndex , setHighlightedIndex ] = useState < number | null > ( null ) ;
6060 const [ expandAll , setExpandAll ] = useState < boolean > ( false ) ;
61+ const [ autoScroll , setAutoScroll ] = useState < boolean > ( true ) ;
6162 const scrollPositions = useRef < { pretty : number ; raw : number } > ( {
6263 pretty : 0 ,
6364 raw : 0 ,
@@ -189,11 +190,16 @@ export function LogView({ logs, isRunning, onClearLogs }: LogViewProps) {
189190 return processed ;
190191 } , [ logs ] ) ;
191192
192- // Track scroll position continuously
193+ // Track scroll position and auto-scroll state
193194 useEffect ( ( ) => {
194195 const handleScroll = ( ) => {
195196 if ( scrollRef . current ) {
196197 scrollPositions . current [ viewMode ] = scrollRef . current . scrollTop ;
198+
199+ // Check if user is near the bottom (within 100px)
200+ const { scrollTop, scrollHeight, clientHeight } = scrollRef . current ;
201+ const isNearBottom = scrollHeight - scrollTop - clientHeight < 100 ;
202+ setAutoScroll ( isNearBottom ) ;
197203 }
198204 } ;
199205
@@ -216,12 +222,17 @@ export function LogView({ logs, isRunning, onClearLogs }: LogViewProps) {
216222 }
217223 } , [ viewMode ] ) ;
218224
219- // Auto-scroll to bottom when new logs arrive (only in pretty mode)
225+ // Auto-scroll to bottom when new logs arrive
220226 useEffect ( ( ) => {
221- if ( scrollRef . current && viewMode === "pretty" ) {
222- scrollRef . current . scrollTop = scrollRef . current . scrollHeight ;
227+ if ( scrollRef . current && autoScroll ) {
228+ // Use requestAnimationFrame to ensure DOM is updated with new content
229+ requestAnimationFrame ( ( ) => {
230+ if ( scrollRef . current ) {
231+ scrollRef . current . scrollTop = scrollRef . current . scrollHeight ;
232+ }
233+ } ) ;
223234 }
224- } , [ viewMode ] ) ;
235+ } , [ autoScroll ] ) ;
225236
226237 if ( logs . length === 0 && ! isRunning ) {
227238 return (
0 commit comments