Skip to content

fix(cli): prevent UI reset and destructive clearing on terminal resize - #18969

Closed
imadraude wants to merge 7 commits into
google-gemini:mainfrom
imadraude:fix/android-termux-ui-reset
Closed

imadraude wants to merge 7 commits into
google-gemini:mainfrom
imadraude:fix/android-termux-ui-reset

Conversation

@imadraude

@imadraude imadraude commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes UI reset issues when resizing the terminal or moving the application to the background. This addresses both Android/Termux specific issues and a general bug where terminal width changes caused destructive screen clearing.

Details

  1. General UI Stability:

    • Resizing the terminal (width change) previously triggered a destructive refreshStatic() call which cleared the terminal screen and remounted the history. This behavior is now disabled when not in alternate buffer mode, as clearing the terminal is undesirable and breaks scrollback.
    • Added a stable key to AppWrapper globally to prevent React component remounting during terminal resize events.
    • Included terminalHeight in the redraw trigger for alternate buffer mode to ensure the UI responds to vertical resizes.
  2. Android/Termux Specifics:

    • Relauncher Loop: Disabled the relauncher for the 'android' platform to prevent duplicate UI elements and repeated auth prompts when Android kills background processes.
    • Suspension Stability: Prevented forced rerender on resume for Android to preserve input state.

Related Issues

Fixes #18914

How to Validate

  1. Run the CLI in any terminal.
  2. Resize the terminal window. The UI should adjust without clearing the entire screen or resetting scrollback (unless in alternate buffer mode).
  3. On Termux, toggle the virtual keyboard. The UI should remain stable.
  4. Move the app to the background and return. The state should be preserved.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • Termux (Android)
    • Ubuntu (Linux)

@imadraude
imadraude requested a review from a team as a code owner February 13, 2026 01:55
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @imadraude, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience for the CLI on Android/Termux by resolving critical UI instability issues. It tackles problems like unwanted component remounts during keyboard interactions and backgrounding, as well as preventing an infinite relaunch loop that led to duplicate UI. The changes are platform-specific, ensuring that the core functionality remains unaffected on other operating systems while providing a much more robust experience for Android users.

Highlights

  • UI Stability on Android/Termux: Addressed issues causing UI resets and full component remounts on Android/Termux when the virtual keyboard is toggled or the application moves to the background.
  • Relauncher Loop Prevention: Disabled the automatic relaunch mechanism for the 'android' platform to prevent duplicate UI elements and repeated authentication prompts caused by Android killing high-resource child processes.
  • React Component Remounting Fix: Implemented a stable key for the AppWrapper component on Android and conditionally skipped forced rerenders in the useSuspend hook to prevent unnecessary React component remounts during terminal resizing events.
Changelog
  • packages/cli/src/gemini.tsx
    • Assigned a stable key prop to AppWrapper specifically for the Android platform to prevent unnecessary component remounts.
  • packages/cli/src/ui/hooks/useSuspend.ts
    • Modified the useSuspend hook to conditionally skip forcing a rerender on the Android platform, addressing UI instability.
  • packages/cli/src/utils/relaunch.ts
    • Introduced a platform check to disable the automatic relaunch mechanism for Android, preventing duplicate UI and auth prompts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces targeted fixes for UI stability issues on Android/Termux. The changes to provide a stable React key and skip forced re-renders are well-implemented and directly address the UI remounting problem. Disabling the relauncher for Android is also a good approach to prevent restart loops. However, I've identified a high-severity issue where disabling the relauncher also removes crucial error handling. My review includes a suggestion to restore this error handling to ensure process failures are caught and reported correctly on Android.

Comment thread packages/cli/src/utils/relaunch.ts Outdated
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels Feb 13, 2026
@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several fixes to improve the user experience on Android/Termux by preventing UI resets and relaunch loops. The changes involve adding a stable React key, skipping forced re-renders on resume, and disabling the process relauncher specifically for the Android platform. The approach is sound. My feedback focuses on improving maintainability by removing code duplication and centralizing platform detection logic, including a suggestion to use the node: prefix for built-in modules for consistency.

Comment thread packages/cli/src/gemini.tsx Outdated
Comment thread packages/cli/src/utils/relaunch.ts Outdated
@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request provides targeted fixes for issues encountered on Android/Termux. It addresses an infinite relaunch loop by conditionally disabling the relauncher on the Android platform. It also resolves UI instability and remounting issues by introducing a stable React key for the root application component and preventing a forced re-render upon resuming the application. The platform detection logic is cleanly abstracted into a new utility. The changes are logical, well-implemented, and effectively resolve the reported bugs.

@imadraude imadraude changed the title fix(cli): prevent UI reset and duplicate relaunch on Android/Termux fix(cli): prevent UI reset and destructive clearing on terminal resize Feb 13, 2026
@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several fixes to improve UI stability, especially on terminal resize and for Android/Termux environments. The changes to prevent destructive screen clearing and disable the relauncher on Android are well-implemented. I have one point of feedback regarding the implementation of a stable key which is described as a global fix but appears to be conditional for Android. This could mean the UI instability on resize persists for other platforms, which goes against maintaining consistent UI behavior across components.

Comment thread packages/cli/src/gemini.tsx Outdated
Comment on lines +272 to +275
<AppWrapper key={isAndroid ? 'android-root' : undefined} />
</React.StrictMode>
) : (
<AppWrapper />
<AppWrapper key={isAndroid ? 'android-root' : undefined} />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request description mentions adding a stable key to AppWrapper globally to prevent remounting on resize, which is listed under "General UI Stability". However, the key is only applied conditionally for Android. If the goal is to ensure UI stability on resize for all platforms, this key should be applied unconditionally. If this is intended to be an Android-only fix, the description should be updated to avoid confusion.

Suggested change
<AppWrapper key={isAndroid ? 'android-root' : undefined} />
</React.StrictMode>
) : (
<AppWrapper />
<AppWrapper key={isAndroid ? 'android-root' : undefined} />
<AppWrapper key="app-root" />
</React.StrictMode>
) : (
<AppWrapper key="app-root" />
References
  1. Maintain consistency with existing UI behavior across components. Defer non-standard UX pattern improvements to be addressed holistically rather than in a single component.

@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several valuable improvements to the CLI's UI stability, particularly concerning terminal resizing and process suspension. The changes to prevent destructive screen clearing when resizing outside of alternate buffer mode and the stabilization of the React component tree using a static key are excellent. The platform-specific fix to disable the relauncher on Android to prevent process loops is also a crucial addition.

I've found one potential issue related to resuming from a suspended state that could lead to unintended screen clearing, and I've left a specific comment with a suggestion. Otherwise, the changes are well-implemented and address the core issues described.

Comment thread packages/cli/src/ui/hooks/useSuspend.ts Outdated
Comment on lines 112 to 114
setImmediate(() => {
refreshStatic();
setForceRerenderKey((prev) => prev + 1);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This unconditional call to refreshStatic() on resume from suspend can be destructive. When not in alternate buffer mode, refreshStatic() clears the entire terminal screen, which is likely not the intended behavior when resuming. The process.stdout.emit('resize') on line 109 should be sufficient to trigger a repaint of the UI via Ink's internal handling and the useEffect hook in AppContainer that listens for terminal size changes. That hook already correctly guards the call to refreshStatic to only run in alternate buffer mode. This explicit call is either redundant (in alternate buffer mode) or destructive (when not in alternate buffer mode) and should be removed.

@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several fixes to improve UI stability, particularly when the terminal is resized or when running on Android. The changes prevent destructive screen clearing and component remounts by using a stable key for the root component and conditionally refreshing the UI. It also disables the app relauncher on Android to prevent problematic loops. While the approach is sound, a critical issue has been introduced in useSuspend.ts where removed props are still referenced in a useEffect dependency array, which will cause a runtime error. This needs to be addressed.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/cli/src/ui/hooks/useSuspend.ts (35-36)

critical

These props have been removed from the function signature, but they are still referenced in the useEffect dependency array on lines 135-136. This will cause a ReferenceError at runtime because the variables are no longer in scope. Please remove them from the dependency array to resolve this critical bug.

@imadraude

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses UI instability issues during terminal resizing and application suspension, particularly on Android/Termux. The changes are well-structured and follow best practices. Using a stable React key for AppWrapper correctly prevents unnecessary component remounts. The logic to conditionally refresh the UI on resize only when in alternate buffer mode is a solid improvement that preserves scrollback history. Furthermore, disabling the auto-relauncher on Android is a direct and appropriate fix for the described relaunch loop. The overall implementation is clean and significantly improves the user experience under the specified conditions. I have no major concerns with this patch.

@gemini-cli

gemini-cli Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your contribution to Gemini CLI. We really appreciate the time and effort you've put into this pull request.

To keep our backlog manageable and ensure we're focusing on current priorities, we are closing pull requests that haven't seen maintainer activity for 30 days. Currently, the team is prioritizing work associated with 🔒 maintainer only or help wanted issues.

If you believe this change is still critical, please feel free to comment with updated details. Otherwise, we encourage contributors to focus on open issues labeled as help wanted. Thank you for your understanding!

@cocosheng-g

Copy link
Copy Markdown
Contributor

@imadraude, apologies for the bot closing this PR! We have reopened it. Please sync your branch to the latest main and we will have someone review it shortly.

@gemini-cli gemini-cli Bot added the help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! label Apr 9, 2026
@scidomino

Copy link
Copy Markdown
Collaborator

closing due to lack of response

@scidomino scidomino closed this May 11, 2026
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android/Termux] Fix duplicate UI and repeated auth prompts caused by relauncher loop and resize remounting

4 participants