fix(dashboard): follow the newest line again after the log list clears

A reader who scrolled up stayed unpinned across a new follow run or a
new filter, so the fresh list sat at its top while lines streamed in
below. An empty list now means the reader is back at the bottom.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-04 05:50:33 +07:00
1 parent b05323f6be
commit 84ed3aaefd
2 files changed
+18 -1

No files matched your search

@@ -31,4 +31,20 @@ describe("LogLines", () => {
expect(list.scrollTop).toBe(120)
})
it("follows again once the list is cleared for a new run", () => {
const { rerender } = render(<LogLines entries={[entry(1)]} />)
const first = screen.getByRole("list")
sized(first, 500)
first.scrollTop = 120
fireEvent.scroll(first)
rerender(<LogLines entries={[]} />)
rerender(<LogLines entries={[entry(2)]} />)
const second = screen.getByRole("list")
sized(second, 300)
rerender(<LogLines entries={[entry(2), entry(3)]} />)
expect(second.scrollTop).toBe(300)
})
})
@@ -9,7 +9,8 @@ export function LogLines({ entries }: { entries: LogEntry[] }) {
const pinned = useRef(true)
useEffect(() => {
if (ref.current && pinned.current) ref.current.scrollTop = ref.current.scrollHeight
if (entries.length === 0) pinned.current = true
else if (ref.current && pinned.current) ref.current.scrollTop = ref.current.scrollHeight
}, [entries])
if (entries.length === 0) return <p className="text-sm text-slate-500">No log lines for this range and filter.</p>