Skip to content

Commit bbccfa5

Browse files
authored
Merge pull request #22 from iskandervdh/fix-scroll-to-bottom
Fix scroll behaviour logs
2 parents 63d21e1 + b2ac408 commit bbccfa5

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

frontend/src/sections/logs-popover.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function LogsPopover() {
2222

2323
const scrollToBottom = useCallback(() => {
2424
setTimeout(() => {
25-
logsRef.current?.scrollTo(0, logsRef.current.scrollHeight);
25+
logsRef.current?.scrollTo({ top: logsRef.current.scrollHeight });
2626
}, 10);
2727
}, [logsRef]);
2828

@@ -35,13 +35,9 @@ export function LogsPopover() {
3535

3636
FollowProjectLogs(currentProject);
3737

38-
const logBuffer: string[] = [];
39-
let bufferTimeout: NodeJS.Timeout | null = null;
40-
41-
const flushBuffer = () => {
38+
const stopListeningForLogs = EventsOn('log', (newLogs: string) => {
4239
setAnsiLogs((prevLogs) => {
43-
const logs = prevLogs + logBuffer.join('');
44-
logBuffer.length = 0;
40+
const logs = prevLogs + newLogs;
4541

4642
// Limit logs to LOG_SIZE_LIMIT characters to prevent browser from freezing
4743
if (logs.length > LOG_SIZE_LIMIT) {
@@ -50,16 +46,6 @@ export function LogsPopover() {
5046

5147
return logs;
5248
});
53-
54-
bufferTimeout = null;
55-
};
56-
57-
const stopListeningForLogs = EventsOn('log', (newLogs: string) => {
58-
logBuffer.push(newLogs);
59-
60-
if (!bufferTimeout) {
61-
bufferTimeout = setTimeout(flushBuffer, 100);
62-
}
6349
});
6450

6551
const scrollListener = (e: Event) => {
@@ -84,7 +70,7 @@ export function LogsPopover() {
8470
if (followLogs) {
8571
scrollToBottom();
8672
}
87-
}, [followLogs, scrollToBottom, logsRef.current?.scrollHeight]);
73+
}, [followLogs, scrollToBottom, logsRef.current?.scrollHeight, ansiLogs]);
8874

8975
if (!currentProject) return null;
9076

0 commit comments

Comments
 (0)