fix(renderer): make ScrollBox defaults sane#79
Conversation
Co-Authored-By: Mark <psyhik17@gmail.com> Co-Authored-By: Codex <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1499af4e83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function clampScrollTop(el: DOMElement, y: number): number { | ||
| const target = Math.floor(y) | ||
| if (!Number.isFinite(target)) return 0 | ||
| return Math.max(0, Math.min(getScrollMax(el), target)) |
There was a problem hiding this comment.
Preserve requested scrolls until fresh layout bounds exist
When this runs before the first renderer pass or immediately after children grow, scrollHeight and scrollViewportHeight are still unset or stale because the renderer refreshes them later in render-node-to-output. Clamping here makes mount-time scrollTo(10) collapse to 0 and can truncate scrollBy during the same commit to the old max, so the later render no longer has the caller's requested target to clamp against fresh Yoga bounds; before this change the requested offset/delta survived until render-time clamping.
Useful? React with 👍 / 👎.
Co-Authored-By: Mark <psyhik17@gmail.com> Co-Authored-By: Codex <noreply@anthropic.com>
Summary
<ScrollBox>layout toflexDirection: 'column'so normal vertical lists/logs produce scrollable content without a workaround.scrollToandscrollBytargets to[0, scrollHeight - viewportHeight]while preserving the existing pending-delta drain path for smooth wheel scrolling.Closes #54.
Closes #74.
Verification
pnpm test -- packages/renderer/src/components/ScrollBox.test.tsxpnpm --filter @yokai-tui/renderer typecheckpnpm --filter @yokai-tui/renderer lintpnpm --filter @yokai-tui/renderer buildgit diff --check