Skip to content

fix(ui): revert preview theme on dialog unmount#22542

Closed
JayadityaGit wants to merge 4 commits intogoogle-gemini:mainfrom
JayadityaGit:fix-theme-dialog-ctrl-c
Closed

fix(ui): revert preview theme on dialog unmount#22542
JayadityaGit wants to merge 4 commits intogoogle-gemini:mainfrom
JayadityaGit:fix-theme-dialog-ctrl-c

Conversation

@JayadityaGit
Copy link
Copy Markdown
Contributor

@JayadityaGit JayadityaGit commented Mar 15, 2026

Summary

Fixes a bug where quitting the CLI while previewing a theme in the Theme Dialog leaves the preview theme applied globally on exit.

Related Issues

Fixes #22541

How to Validate

  1. Start the CLI with npm run start.
  2. Open the Theme Dialog using /theme.
  3. Arrow down to highlight a different theme (observe the preview changes).
  4. Do NOT press Enter.
  5. Press Ctrl+C twice to exit the CLI.
  6. Verify that the "Goodbye" message and your terminal prompt use the originally saved theme, not the preview theme.

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:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

- Track original theme on mount
- Revert to original theme if unmounted without a selection
- Add test case verifying reversion behavior

Addresses an issue where exiting the CLI while previewing a theme
leaves the preview theme applied to the terminal state.
@JayadityaGit JayadityaGit requested a review from a team as a code owner March 15, 2026 15:06
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses a bug where previewed themes in the CLI's Theme Dialog would incorrectly remain active after the application was exited without the user explicitly selecting a theme. The changes ensure that the terminal's appearance consistently reflects the user's saved theme upon exit, even if a theme was being previewed.

Highlights

  • Theme Reversion Logic: Implemented a mechanism to track the original theme and whether a new theme was explicitly selected within the ThemeDialog. If the dialog unmounts without an explicit selection, the theme is automatically reverted to the original one.
  • Exit Cleanup Integration: Ensured that the ThemeDialog is properly closed during the application's quit process, preventing the previewed theme from persisting globally if the user exits the CLI while previewing themes.
  • Test Coverage: Added a new test case to verify that the theme correctly reverts to the original state when the ThemeDialog is unmounted without a theme being explicitly selected.
Changelog
  • packages/cli/src/ui/AppContainer.tsx
    • Added a call to closeThemeDialog() when the application quits to ensure proper cleanup.
    • Included closeThemeDialog in the dependency array for relevant hooks.
  • packages/cli/src/ui/components/ThemeDialog.test.tsx
    • Added a new test case to confirm that the theme reverts to the original setting when the dialog unmounts without an explicit selection.
  • packages/cli/src/ui/components/ThemeDialog.tsx
    • Imported useEffect and useRef hooks from React.
    • Introduced originalThemeRef to store the theme active when the dialog mounts.
    • Added isSelectedRef to track if a theme has been explicitly chosen by the user.
    • Implemented a useEffect hook with a cleanup function that reverts the theme to the originalThemeRef value if isSelectedRef is false upon unmount.
    • Modified handleThemeSelect and handleScopeSelect callbacks to set isSelectedRef.current to true when a theme or scope is explicitly selected.
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.

Copy link
Copy Markdown
Contributor

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

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 correctly fixes a bug where a previewed theme would persist after quitting the CLI. The use of a useEffect cleanup hook in ThemeDialog is a good approach to ensure the theme is reverted on unmount. However, the current implementation introduces a subtle bug due to a stale closure, where it may revert to an outdated theme if settings change while the dialog is open. I've provided a comment with a suggested fix to address this. The accompanying test and the change to the quit command handler are appropriate.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 15, 2026
@JayadityaGit
Copy link
Copy Markdown
Contributor Author

JayadityaGit commented Mar 15, 2026

I self reviewd my changes so that it will be easier for reviewers to understand why I did those changes

Copy link
Copy Markdown
Contributor

@psinha40898 psinha40898 left a comment

Choose a reason for hiding this comment

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

Some food for thought

useEffect shouldn't be used this way. i see two potential paths here

  1. putting the logic inside an event handler
  2. a deeper refactor -- this may or may not result in the logic ending up in an event handler (probably yes). i would need to do a deeper review of how this component works

for now I think you could look into whether we can fix this through event handler and also read the linked article.

are there other paths that are properly reverting the preview theme?

I do plan to look at this component deeper within a few days here since it is related to Settings

JayadityaGit and others added 2 commits March 17, 2026 16:26
Removes the useEffect and related useRef hooks used for resetting
the theme on unmount in ThemeDialog. The theme reset is already handled
correctly by the closeThemeDialog event handler, which is now called
explicitly during the application quit sequence. This simplifies the
component and adheres to React best practices by relying on event
handlers for user-initiated actions.
@JayadityaGit
Copy link
Copy Markdown
Contributor Author

Some food for thought

useEffect shouldn't be used this way. i see two potential paths here

1. putting the logic inside an event handler

2. a deeper refactor -- this may or may not result in the logic ending up in an event handler (probably yes). i would need to do a deeper review of how this component works

for now I think you could look into whether we can fix this through event handler and also read the linked article.

are there other paths that are properly reverting the preview theme?

I do plan to look at this component deeper within a few days here since it is related to Settings

speaking of settings , I was working on a crucial UX bug i found related to settings, if you are intersted you can check this out #22788 @psinha40898

A new perspective on my changes really helps me out

thank you.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 30, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@gemini-cli gemini-cli bot closed this Mar 30, 2026
@cocosheng-g
Copy link
Copy Markdown
Contributor

@JayadityaGit, thank you for your contribution! We've reviewed the approach in this PR and decided to keep it closed because using useEffect this way is an anti-pattern for this scenario. The logic should be placed inside an event handler instead. We still welcome improvements here using a different approach! Feel free to open a new PR if you're interested.

@JayadityaGit
Copy link
Copy Markdown
Contributor Author

JayadityaGit commented Apr 8, 2026

@cocosheng-g please have a look into it again, i am using existing event handlers here as far as i remember, all the anitpatterns of useffect should be gone, thanks to @psinha40898

@psinha40898
Copy link
Copy Markdown
Contributor

Yes cocosheng I wonder if the stale PR description miscommunicated things

iirc the PR is now using the action registry to execute the logic on user press, akin to an event handler

@JayadityaGit might be worth updating the PR description too

@JayadityaGit
Copy link
Copy Markdown
Contributor Author

JayadityaGit commented Apr 8, 2026

updated the description . i have deleted my original invalid assumptions to prevent confusion, and kept what is needed. thanks

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theme Dialog preview theme is not reverted when quitting via double Ctrl+C and Ctrl+D

3 participants