fix(tui): stale content after tree navigation#2126
Open
Perlence wants to merge 1 commit intobadlogic:mainfrom
Open
fix(tui): stale content after tree navigation#2126Perlence wants to merge 1 commit intobadlogic:mainfrom
Perlence wants to merge 1 commit intobadlogic:mainfrom
Conversation
When navigating the session tree, transient UI components (tree selector, extension selector) inflate maxLinesRendered beyond the actual content height. After navigation, the differential renderer checked whether firstChanged was above the viewport using previousLines.length - height, which underestimated the true viewport position. This caused it to enter the differential path instead of doing a full re-render, leaving old branch content (summary, messages) on screen. Repeated navigation duplicated the stale content. Fix: use prevViewportTop (derived from maxLinesRendered) for the above-viewport check so the renderer correctly falls back to fullRender when firstChanged is above the actual viewport.
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
When navigating the session tree with "No summary", stale messages from the old branch remain on screen and duplicate on repeated navigation.
Here's a repro case that the clanker has crafted:
repro-stale-tree-nav.zip
And here's the recording of the bug in that session and the fix:
Screen.Recording.2026-03-14.at.17.25.57.mov
Root cause
The differential renderer decides whether to fall back to
fullRenderby checking iffirstChangedis above the viewport:This uses
previousLines.lengthto estimate the viewport position. ButmaxLinesRendered, which determines the actual viewport, can be larger thanpreviousLines.lengthwhen transient UI components (tree selector, extension selector) inflated it during the same interaction. The tree selector adds ~40 extra lines, then closes, butmaxLinesRendereddoesn't shrink.This was done in 0925faf which changed the check from
firstChanged < viewportTop(usingmaxLinesRendered) tofirstChanged < previousContentViewportTop(usingpreviousLines.length) to avoid false positive redraws when appending lines after content shrunk. However, the differential renderer genuinely can't address lines abovemaxLinesRendered - height.Fix
Use
prevViewportTop(derived frommaxLinesRendered) for the check, restoring the original correct behavior:This may trigger a few more
fullRendercalls whenmaxLinesRenderedis inflated, but those redraws are necessary for correctness.