How to build an accessible LogViewer in React

The scroll region is role="log" with aria-live="polite" so assistive tech announces new output without stealing focus; the container is keyboard-scrollable and a visually-hidden live status reports the line count; color is paired with level semantics, never the sole encoding

When to use a LogViewer

When not to use it

Keyboard interactions

Role log, verified at WCAG 2.2-AA.

Common mistakes

Avoid: logsSignal.value = [...logsSignal.value.slice(1), line]

Prefer: const logs = useStreamBuffer({ capacity: 1000 }); logs.append(line)

The slice pattern reallocates the whole array per line (O(n)) and renders per line; the stream buffer is O(1) and renders once per frame

Example

const logs = useStreamBuffer<LogLine>({ capacity: 1000 })
// socket.onmessage = (e) => logs.append({ id: seq++, text: e.data })
<LogViewer lines={logs.signal} />

See the full LogViewer reference →