opentui(v6): clamp negative draw coords at the node:ffi seam (diff crash fix)
Expanding a tall <diff showLineNumbers> pinned to the scrollbox bottom froze the TUI with ERR_INVALID_ARG_VALUE looping out of CliRenderer.loop every frame. Root cause: @opentui/core 0.4.0 marshals OptimizedBuffer fillRect/drawText/setCell* coordinates as u32 in the FFI table while LineNumberRenderable.renderSelf passes raw screen coordinates — NEGATIVE when the diff is partially scrolled above the viewport. Bun's FFI silently wraps negatives (native side bounds-checks them into a no-op); Node's experimental node:ffi rejects them. bufferDrawBox already uses i32, which is why ordinary boxes/text scroll fine and only the diff line-background path crashed. Fix at the seam we own: boundary/ffiSafe.ts patches OptimizedBuffer to clip fillRect to the non-negative quadrant and skip negative-origin drawText/setCell*/drawChar before the FFI call (Bun parity). Installed from boundary/renderer.ts (live) and test/lib/render.ts (headless). TODO(upstream): widen those FFI params to i32 so this shim can be deleted.
This commit is contained in:
@@ -23,6 +23,13 @@ import { testRender, useRenderer } from '@opentui/solid'
|
||||
import type { JSX } from '@opentui/solid'
|
||||
import { createMemo } from 'solid-js'
|
||||
|
||||
import { installFfiCoordSafety } from '../../boundary/ffiSafe.ts'
|
||||
|
||||
// Headless renders go through the same node:ffi seam as the live TUI — install
|
||||
// the negative-coordinate shim here too (the live path installs it in
|
||||
// boundary/renderer.ts, which tests don't import).
|
||||
installFfiCoordSafety()
|
||||
|
||||
/** Wrap a node in a KeymapProvider whose keymap is bound to the test renderer. */
|
||||
function withKeymap(node: () => JSX.Element): () => JSX.Element {
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user