Skip to content

fix(hr): stop adding a resize listener per horizontal rule - #57

Merged
denolfe merged 1 commit into
mainfrom
fix/hr-resize-listeners
Sep 7, 2026
Merged

denolfe merged 1 commit into
mainfrom
fix/hr-resize-listeners

Conversation

@denolfe

@denolfe denolfe commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

What was wrong: Hr got its width from useTerminalDimensions(), which adds a resize listener to the renderer every time it is called — so one listener per --- in the document.

Why it matters: Once the count passes 10, Node prints a MaxListenersExceededWarning to stderr, on top of the running TUI. That is the visible column shift while scrolling. A 15-rule document held 22 listeners.

The fix: Hr now reads contentWidth from useAppState(), like Table, CodeBlock and Frontmatter already do. No listener. Same document now holds 7.

The test: mounts a 2-rule and a 40-rule document and asserts the listener count is the same and under 10.

`useTerminalDimensions` subscribes to the renderer's `resize` event once per
call site, so every horizontal rule in a document added a listener. Past 10,
Node prints a MaxListenersExceededWarning to stderr — over the live TUI, which
shifts the screen mid-scroll. A document with 15 rules held 22 listeners.

`Hr` now reads `contentWidth` from `AppStateContext`, as `Table`, `CodeBlock`
and `Frontmatter` already do, and sizes the rule to the content column instead
of the terminal width it relied on the box to clip.
@denolfe denolfe changed the title fix(hr): size rules from context instead of a resize subscription fix(hr): stop adding a resize listener per horizontal rule Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Startup benchmark (--render test/exhaustive.md, linux-x64)

build mean ratio verdict
baseline (main@b7ab07d) 363.7ms ± 8.1ms —
PR 360.4ms ± 10.6ms 0.99× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

First-frame (large.md, runs=10)

metric baseline (main@b7ab07d) PR ratio verdict
first-frame 272.2ms 266.1ms 0.98× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

Scroll (large.md)

metric baseline (main@b7ab07d) PR ratio verdict
full_mount 10277.0ms 10292.0ms 1.00× ✅ ok
step_p50 22.0ms 22.4ms 1.02× ✅ ok
step_search_p50 22.7ms 23.2ms 1.02× ✅ ok
stepMatch_p50 16.4ms 17.4ms 1.06× ✅ ok
commit 139.7ms 147.4ms 1.06× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

@denolfe
denolfe merged commit beedc6d into main Sep 7, 2026
8 checks passed
@denolfe
denolfe deleted the fix/hr-resize-listeners branch September 7, 2026 04:10
denolfe added a commit that referenced this pull request Sep 9, 2026
- feat: copy selected text (#58) (a9f836e)
- fix(hr): stop adding a resize listener per horizontal rule (#57) (beedc6d)
- ci: add first-frame and scroll benchmarks to the PR bench job (#56) (b7ab07d)
- perf: improve first frame and progressive-mount speed, optimize large documents (#54) (3b6d9f2)
- chore(ci): pin bun 1.4.1 via mise (#53) (f596175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant