fix: support nested StaticRender objects and optimize StaticRender API to ensure elements are really removed from the DOM.#99
Conversation
| trackSelection, | ||
| } = options; | ||
|
|
||
| const callBeforeRender = (n: DOMElement) => { |
There was a problem hiding this comment.
this was no longer needed
refactor: simplify StaticRender layout computation Moved StaticRender's layout evaluation to prepareYogaTree inside ink.tsx. This avoids repeatedly evaluating static subtrees during the main layout loop, treating nested and cached StaticRender components as efficient, fixed-size leaf nodes. fix: address PR review feedback fix: lint errors chore: update selection snapshot refactor: Update StaticRender to take a callback for children Tweak example. fix(worker): expand root region when rendering backbuffer lines This fixes an issue where nested scrollable regions with overflowToBackbuffer=true would not render their newly revealed lines into the backbuffer because the root region artificially clipped the rendering canvas to the terminal height. By passing overrideHeight and isExpanded=true to the root region composeNode call during getLinesForScroll, the scrollable region receives the expanded context and correctly renders its off-screen lines, which are then successfully captured and written to the terminal history. Tests to reproduce issues.
|
Overall, this is an excellent PR. Evaluating the layout for the static subtree inside Here are a few points to consider: 1. Breaking API ChangeChanging
2. Potential Memory Leak in Region.nodeThe cached 3. Excellent
|
17618a7 to
2287716
Compare
Update cachedStickyHeaders mapping in render-node-to-output to set 'node: undefined' to drop the retained reference to the DOM element after computing the sticky header layout cache. Update all usages to handle the optional stickyNode property and resolve max-params typescript errors.
…nk#99 Change StaticRender children from ReactNode to () => ReactNode so React stops reconciling the subtree once the cached render is ready. Add internal_onRendered callback on DOMElement, invoked by prepareYogaTree() after caching, which sets isRendered state to skip children on subsequent renders. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add instruction to explicitly avoid destructured objects for resolving max-params linting errors in hot-path rendering code, instead preferring to ignore the linter rule due to GC allocation overhead.
I tried multiple ways to optimize this and this one appears to be have been the most robust while performant.
I was also tempted to create a version that aligned a bit more when Ink's existing rendering support
but performance was poor when I tried to implement that way. I'm not exactly clear why it didn't work well but performance
was bad using the nestedStatic example to test performance. Starting up that example took multiple seconds while it is
basically instant with this approach.
Nested static items isn't a truly crucial feature but is a good test to make sure the static rendering is robust.
The most useful part of this change is switching so we fully evict statically rendered items from the virtual DOM. We weren't
doing enough of that previously resulting in performance struggles seen in GeminiCLI handling a DOM with a large number of statically rendered elements.
Moved StaticRender's layout evaluation to prepareYogaTree inside ink.tsx. This avoids repeatedly evaluating static subtrees during the main layout loop, treating nested and cached StaticRender components as efficient, fixed-size leaf nodes.
This fixes an issue where nested scrollable regions with overflowToBackbuffer=true would not render their newly revealed lines into the backbuffer because the root region artificially clipped the rendering canvas to the terminal height. By passing overrideHeight and isExpanded=true to the root region composeNode call during getLinesForScroll, the scrollable region receives the expanded context and correctly renders its off-screen lines, which are then successfully captured and written to the terminal history.
Tests to reproduce issues.