#1526·opentui

ScrollBox scrollbar thumb is too short on first render with all items present

Author: konmikCreated Sep 22, 2026Updated Sep 22, 2026

Description

A ScrollBox containing nine items renders an incorrectly short scrollbar thumb even though seven of the nine items are visible.

All items are added before the first render. There is no asynchronous loading, subsequent content update, or manual assignment of scrollbar dimensions.

After the first render, the scrollbar reports the correct content and viewport dimensions, but its slider has an incorrect viewport size:

Measurement Expected Actual
Content height 18 rows 18 rows
Viewport height 14 rows 14 rows
Scroll range 4 rows 4 rows
slider.viewPortSize 14 0.01
Thumb ratio before cell rounding 77.8% 20%

The thumb should occupy most of the track, since only two of nine items are hidden.

Environment

  • Regression test run against OpenTUI v0.5.12 source, updated to upstream commit b4afd3d9*
  • Bun 1.4.2
  • Regression test platform: Windows
  • Also reproduced in an application dropdown using OpenTUI 0.5.10, with a headless render under Arch Linux on WSL2

* The local checkout preserves two pre-existing commits: a Solid test addition and its revert. The relevant scrollbar implementation matches upstream.

Failing regression test

File: packages/core/src/tests/scrollbox-thumb.test.ts

typescript
import { expect, test } from "bun:test"
import { createTestRenderer } from "../testing/test-renderer.js"
import { ScrollBoxRenderable } from "../renderables/ScrollBox.js"
import { TextRenderable } from "../renderables/Text.js"

test("ScrollBox sizes its initial scrollbar thumb for seven visible items out of nine", async () => {
  const { renderer, renderOnce } = await createTestRenderer({ width: 80, height: 24 })

  try {
    const scrollbox = new ScrollBoxRenderable(renderer, {
      width: 30,
      maxHeight: 14,
      horizontalScrollbarOptions: { visible: false },
    })
    renderer.root.add(scrollbox)

    // All nine items exist before the first layout; none are loaded later.
    for (let index = 0; index < 9; index++) {
      scrollbox.add(
        new TextRenderable(renderer, {
          content: `Item ${index + 1}`,
          height: 2,
          flexShrink: 0,
        }),
      )
    }

    await renderOnce()

    const scrollbar = scrollbox.verticalScrollBar
    expect(scrollbar.scrollSize).toBe(18)
    expect(scrollbar.viewportSize).toBe(14)
    expect(scrollbar.slider.max - scrollbar.slider.min).toBe(4)

    // With 7/9 of the items visible, thumb sizing must use the full 14-row viewport.
    expect(scrollbar.slider.viewPortSize).toBe(14)
  } finally {
    renderer.destroy()
  }
})

Run from packages/core:

bash
bun test src/tests/scrollbox-thumb.test.ts

Observed failure:

Expected: 14
Received: 0.01

0 pass
1 fail
4 expect() calls

Expected behavior

On the initial render, the scrollbar thumb should represent the visible-to-total content ratio: 14 / 18 ≈ 77.8%.

Diagnosis

Slider.viewPortSize clamps the supplied viewport size to the slider's current range. For a scrollbar, that range is content height minus viewport height, so it is not a valid upper bound for the viewport size.

The initial layout leaves slider.viewPortSize at 0.01, despite ScrollBar.viewportSize correctly reporting 14. The thumb calculation then treats the slider viewport as at least 1, producing 1 / (4 + 1) = 20% instead of 14 / 18.

The test allows ScrollBox to perform its own layout and scrollbar updates; it does not force a particular update sequence.

Related work

PR #1237 — fix(core): longer scroll bar removes the upper clamp and appears to address this cause. This test provides a reproduction using a fully populated ScrollBox on its first render.

An existing Slider test explicitly expects upper clamping, so that expectation will also need updating with the fix.