Repository navigation
fix(terminal): stop the find bar from crashing a node after a narrowing resize - #1313
Merged
Merged
Conversation
…ng resize xterm trims buffer lines on a narrowing resize only for a buffer that reflows, and the alternate buffer (every Claude Code node) never does. The search addon then reads the cut-off cells, computes a negative decoration width for a hit past the right edge, and registerDecoration throws 'This API only accepts positive integers' inside the find-bar effect, so the node's error boundary replaces the whole node. patchShrinkTrim trims the alternate buffer's lines to the new width on a narrowing resize, the same thing xterm does to a reflowing buffer. Wired into TerminalNode and the kanban ModalTerminal.
…ote why only the alt buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1312
Typing in the find bar of a Claude Code node that had been made narrower replaced the node with "This node hit an error — This API only accepts positive integers". The cause is in xterm: on a narrowing resize it trims buffer lines only when the buffer reflows, and the alternate buffer never does, so the search addon reads cells past the right edge and computes a negative decoration width. Details are in the issue.
Change
terminal/shrink-trim.ts,patchShrinkTrim(term): on a resize that narrows the terminal, the alternate buffer's lines are trimmed to the new width. That is the same call (BufferLine.resize) xterm makes for a buffer that reflows. The trimmed cells are past the right edge, so they are not on screen; after widening they come back blank, as they do in a reflowing buffer, instead of showing the old text until the app repaints.TerminalNodeon a fresh xterm before the first fit (a parked xterm already has it), and in the kanbanModalTerminalbefore its fit.patchViewportScrollSync: if the private fields are missing on another xterm version, it leaves stock behavior; a second call is a no-op.scrollback: 0orwindowsPty, the two things that turn reflow off.Alternative considered
Guarding the search side instead is possible, but skipping the bad decoration alone is not enough: the addon would still count text that is no longer on screen as hits, and its row loop would carry the negative width over into a highlight on the next row. A search-side fix would have to bound hits and row continuation as well, inside the addon. Trimming removes the stale text where it comes from, and also fixes the widening case.
Checks
shrink-trim.test.ts, with a real xterm and the real search addon in jsdom: the crash reproduces without the patch; with it a find no longer throws, cut-off text is no longer counted as a hit, a hit still on screen is still found, widening shows blank cells instead of the cut-off text, a wide character cut by the new edge, the normal buffer needs no patch, idempotence and fail-open; plus source pins that both terminals call it.vitest run src/renderer: 9010 passed (run before the wide-character test was added;shrink-trim.test.tsnow has 10 tests, all passing). The 5 failures are insessionRename.realtty.test.ts(posix_spawnp failed) and fail the same way without this change, because node-pty in this checkout is built for Electron.npm run typecheck: clean.Not checked
_core.buffers,BufferLine.resize). The fail-open guard only covers missing fields, not changed behavior, so an xterm upgrade should rerun these tests; they use the real xterm, so they would show it.