fix(tui): paint cached highlights on the first frame - #46413
Closed
kitlangton wants to merge 1 commit into
Closed
Conversation
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.
Why
Returning to an already-highlighted session still paints code as plaintext before Tree-sitter responds. Cached results need to be available synchronously during the first paint, not just through an awaited promise.
What Changes
A bounded 500-entry Tree-sitter cache supplies completed results to
CodeRenderablebefore layout and paint. Parser/configuration changes and client teardown invalidate it. Cached data is copied so a custom callback cannot modify another view's highlighting.The change is carried as a pinned OpenTUI 0.5.9 patch, with matching Bun/Node implementations. Keeping the lookup in the renderer avoids stale
initialStyledTextvalues when Markdown reuses a node after its content or theme changes. No TUI paint suppression or hidden session trees are added.Demo
cached-highlight-before-after.mp4
Production TUI:
5a4914c670(left) and840ff9306d(right), the same imported nine-line TypeScript fixture at 120x40. Cold code appears as readable plaintext in both. On the warm tab return, the first code frame is already highlighted after the fix. No LLM requests or artificial worker delays; matched 1x/60fps clips with setup and idle gaps trimmed. This demonstrates cached first-paint styling, not throughput or hardware latency. The 500ms footer is fixed fixture history, not switch timing. Settled frames match exactly.Actual warm-return video frame, before the base's colors arrive:
Scope
This replaces the approach in #40698. Cold content stays readable immediately; this PR does not attempt to hide first-time highlighting latency or change streaming policy on cache misses. It is independent of #46145.
Verification
1,011 tests passed, 4 skipped. TUI/CLI typechecks and all 33 pre-push typecheck tasks passed. Controlled tests hold the next highlight promise unresolved and assert both immediate colored cache hits and immediate plaintext misses. Coverage includes nested fences, Write previews, Solid property ordering, first-frame concealment geometry, theme/content/language changes, LRU eviction, parser invalidation, mutable callbacks, and teardown.
A Node-side worker/cache smoke also passed. Native Node painting could not be exercised because OpenTUI 0.5.9 reports that native FFI is unavailable for that runtime; paint tests use the production Bun renderer.