Bug: CLI crashes on input after navigating through chat history
Description
The CLI crashes with a TypeError: Cannot read properties of undefined (reading 'length') when the user attempts to type into the input buffer after a specific sequence of chat history navigation that causes the message currently being typed by user to be lost.
The error originates in text-buffer.js, within the calculateVisualLayout function, which is called by a React component. This suggests a state management issue where the component's state for the input buffer becomes undefined, but the render logic attempts to access its length property.
To Reproduce
Steps to reproduce the behavior:
- Start typing a message into the CLI input.
- Use the
Up Arrowkey to navigate past the current drafted message and into previous chat history entries. - Use the
Down Arrowkey to navigate back down. The message user started typing is now gone. - Attempt to type any character into the now-empty input prompt.
- The CLI immediately crashes with the error.
Logs
The following stack trace points to an error when calculating the layout of the text buffer, which likely occurs when the component tries to render an undefined value.
ERROR Cannot read properties of undefined (reading 'length')
file:///C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/dist/src/ui/components/shared/text-buffer.js:128:21
- (file:///C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/dist/src/ui/components/shared/text-buffer.js:128:21)
- at Array.forEach (<anonymous>)
- calculateVisualLayout (file:///C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/dist/src/ui/components/shared/text-buffer.js:126:18)
- (file:///C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/dist/src/ui/components/shared/text-buffer.js:317:24)
-react-stack-bottom-frame (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:15945:20)
- runWithFiberInDEV (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:1735:30)
-commitHookEffectListMount (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:9516:29)
-commitHookPassiveMountEffect (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:9639:11)
-commitPassiveMountOnFiber (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:11364:13)
-recursivelyTraversePassiveMountEffe (C:/Users/user/AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/react-reconciler/cjs/react-reconciler.development.js:11338:11)
Environment
- CLI Version: 0.1.9
- Git Commit: 34935d6
- Model: gemini-2.5-pro
- Sandbox: no
- OS: win32
- Auth Method: OAuth
- Shell: PowerShell
Additional context
The issue seems to be a state corruption or improper state reset within the React component managing the input prompt. A defensive check to ensure the text buffer state is not undefined before accessing its properties in calculateVisualLayout should resolve the crash.
I've tested and this cannot be reproduced anymore. Please open if you still experience it.