fix(ui): pin composer to terminal bottom — stop layout jitter during streaming#2331
Open
HUQIANTAO wants to merge 1 commit into
Open
fix(ui): pin composer to terminal bottom — stop layout jitter during streaming#2331HUQIANTAO wants to merge 1 commit into
HUQIANTAO wants to merge 1 commit into
Conversation
Set height={terminalRows} on the outermost layout Box and add
overflow=hidden to the content area column. During agent output
streaming, new cards would cause Yoga to recalculate the layout
height, pushing the composer input box up and down.
Now the container height is fixed to the actual terminal rows
(via useTerminalSize()), so the content area is constrained and
the composer stays anchored to the bottom.
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.
Problem
During agent output streaming, the composer input box at the bottom of the terminal moves up and down. This is visually jarring — the user is trying to read streaming output while the input area they will type into next is bouncing around.
Root Cause: Ink/Yoga layout with unconstrained height
The current layout structure in
App.tsx(simplified):Ink uses Yoga (Facebook's flexbox engine) for layout. Yoga calculates the height of each flex container from its children. When the outer container has no explicit
height, Yoga's layout algorithm works as follows:Initial state: content area contains a few settled cards. Total height ≈ 60% of terminal. Composer sits at the bottom with a large gap above it.
Streaming starts: new text lines are appended to the active card.
CardStream's content grows. Yoga recalculates — the content area now needs more vertical space.Layout reflow: since the outer container is unconstrained, Yoga expands it to accommodate the new content. The composer (which sits at the end of the flex column) gets pushed down. The terminal scrolls.
Streaming settles: the active card stops growing. The layout stabilizes. But on the NEXT turn, new cards appear again, causing another reflow.
Bidirectional jitter: When
LiveActivityAreaupdates (progress bar appears/disappears, tool status line changes), the height changes by 1-2 rows. Yoga reflows again → composer shifts by 1-2 rows → visible flicker.The fundamental issue is that Yoga does not know the terminal has a fixed number of rows. Without an explicit
height, it treats the container as infinitely expandable, and every content change triggers a full reflow.Fix
Two properties added to the layout:
1. Fixed outer height via
useTerminalSize()useTerminalSize()is Inks built-in hook that reads the actual TTY dimensions (process.stdout.rows). By passingheight={terminalRows}to the outermost layout Box, we tell Yoga: "this container is exactly N rows tall — no more, no less."Effect: Yoga no longer recalculates the container height when children change. It allocates the fixed
terminalRowsspace, then distributes it among children usingflexGrow/flexShrink. The composer's position is now a function of the terminal size (which only changes on resize), not of the streaming content.2. Overflow clamping on the content area
The
overflow="hidden"property (passed through to Yoga) tells the layout engine: "children may not extend beyond this container's allocated height." Yoga clips content at the boundary.Effect: Even if
CardStreamrenders more cards than fit in the viewport, Yoga does not expand the content area. TheCardStreamcomponent already implements virtual scrolling (it only renders cards within a visible window + buffer), so this acts as a safety net for edge cases where the measured card heights are temporarily inconsistent with actual rendered heights (common during streaming when card heights are being measured for the first time).Why this is beneficial
terminalRowsupdates on next renderPotential downsides — and why they don't apply
1. "What if the terminal is resized?"
useTerminalSize()returns live dimensions. When the user resizes their terminal window, the hook returns the newrowsvalue on the next render. Yoga recalculates the layout with the new height. This is correct behavior — the composer re-anchors to the new bottom.2. "What if
CardStreamvirtual scrolling breaks with a fixed outer height?"CardStreamalready usesouter.height(fromuseBoxMetrics) to compute its visible window. The fixed outer height ensuresouter.heightis stable frame-to-frame, which actually improves virtual scrolling consistency — the visible window boundaries don't oscillate.3. "What about the
StaticCardStreampath (historyScrollMode: "terminal")?"StaticCardStreamuses Inks<Static>component which positions items at absolute coordinates within the container. A fixed-height container is the intended usage pattern for<Static>— it requires a known viewport to correctly map item indices to screen positions. This change makesStaticCardStreamstrictly more correct.4. "Does
useTerminalSize()work in non-TTY environments (piped stdout)?"Yes. Inks
useTerminalSize()falls back toprocess.stdout.columns || 80/process.stdout.rows || 24when stdout is not a TTY. The desktop app (Electron) always uses a pty, so TTY dimensions are always available.5. "Any performance impact?"
No.
useTerminalSize()reads a value that Ink already tracks internally (it's used for the root node height). This is a property read, not a measurement. Theheightandoverflowprops are standard Yoga properties with no additional overhead.Changes
src/cli/ui/App.tsxuseTerminalSize, addheightto outer Box, addoverflowto content BoxTesting
npx reasonix codeRelated
useTerminalSize():packages/ink/src/index.ts:101