Repository navigation
fix: keep terminal search from crashing the surface on narrow viewports - #6852
Conversation
|
Warning Review limit reached
Next review available in: 10 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/TerminalSearch.tsx (1)
53-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a short why-comment where
safeFindis introduced in this component.The crash-guard behavior is non-obvious at these call sites, and this file now depends on that rationale. A brief note near the first
safeFind(...)use is enough.As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
Suggested tweak
const findNext = useCallback(() => { if (searchAddon && requestQuery) { + // Why: xterm can throw while creating search decorations on collapsed or + // narrow viewports; safeFind preserves navigation instead of crashing. safeFind( (term, options) => searchAddon.findNext(term, options), requestQuery, searchOptions() )Also applies to: 89-93
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 50156696-e697-4c97-a882-0c7323622d4d
📒 Files selected for processing (3)
src/renderer/src/components/TerminalSearch.tsxsrc/renderer/src/components/terminal-search-safe-find.test.tssrc/renderer/src/components/terminal-search-safe-find.ts
@xterm/addon-search builds match-highlight decorations whose per-row width is Math.min(terminal.cols - matchCol, remainingSize). When the live viewport is narrower than the buffer column where a match begins — content laid out at a wider width before the pane reflowed, or a collapsed/0-col viewport — that width is negative, and xterm's registerDecoration -> _verifyPositiveIntegers throws 'This API only accepts positive integers' synchronously inside findNext. Thrown from TerminalSearch's effect/handlers, it trips RecoverableRenderErrorBoundary and kills the whole terminal surface (crash report 0b9ab636, Orca 1.4.104). Wrap the addon find calls in safeFind(), which swallows that specific decoration error. Match navigation runs before decoration creation, so search stays functional and only the highlight on the pathological frame is dropped; the next find after a reflow/fit highlights normally. Unrelated errors still propagate. Adds terminal-search-safe-find.test.ts exercising the real helper. Co-authored-by: Orca <[email protected]>
e9b958a to
f30b3e1
Compare
…ts (stablyai#6852) Co-authored-by: Orca <[email protected]>
Problem
Crash channel report (Orca 1.4.104, macOS):
react-error-boundaryon the terminal surface.boundary_id:terminal.workbench,surface:terminal-workbencherror:This API only accepts positive integers_verifyPositiveIntegers ← registerDecoration ← _createResultDecorations ← createHighlightDecorations ← _highlightAllMatches ← SearchAddon.findNext ← TerminalSearch useEffectRoot cause
@xterm/addon-searchbuilds each match-highlight decoration with a per-row width of:When the live viewport is narrower than the buffer column where a match starts — content laid out at a wider width before the pane reflowed, or a collapsed / 0-column viewport —
cols - matchColis negative, so the width is negative. xterm'sregisterDecoration→_verifyPositiveIntegersthen throws synchronously insidefindNext. BecauseTerminalSearchcallsfindNextfrom a React effect/handler, the throw tripsRecoverableRenderErrorBoundaryand kills the whole terminal surface.There's no
patch-packagein this repo, so the fix is app-side.Fix
Wrap the addon
findNext/findPreviouscalls in a smallsafeFind()helper that swallows only this specific decoration error (/only accepts positive integers/i). Match navigation happens before decoration creation inside the addon, so search stays fully functional — we just drop the highlight on that one pathological frame; the next find (after a reflow/fit widens the viewport) highlights normally. Any unrelated error still propagates.Evidence of fix
terminal-search-safe-find.test.tsexercises the realsafeFindhelper (not ported logic):Before the fix, a
findNextthat throwsThis API only accepts positive integerspropagated out ofTerminalSearch's effect into the boundary (the exact reported crash). After the fix it is contained and reported as "no match this frame".ELI5
The terminal's "find" feature draws a colored box around each match. To draw the box it does
box width = screen width − match position. If the window is skinnier than where the match sits, that subtraction goes negative, and the drawing library refuses negative sizes by throwing an error so loud it takes down the whole terminal. We now catch that one specific complaint: search still jumps to the match, we just skip painting the box on that frame instead of blowing up the terminal.Trade-offs
only accepts positive integers) because xterm throws a plainErrorwith no code. If xterm reworded that message, the guard would stop catching it — acceptable for a defensive guard, and the unit test pins the current wording so a dependency bump that changes it is visible.Scope / platforms
Renderer-only; platform-agnostic (applies to local, SSH, and remote terminals — all use the same xterm search addon).
Made with Orca 🐋