Skip to content

fix(tui): stop clobbering theme mode with auto-detected value on every render event#21011

Open
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/tui-theme-mode-kv-pollution
Open

fix(tui): stop clobbering theme mode with auto-detected value on every render event#21011
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/tui-theme-mode-kv-pollution

Conversation

@kevinWangSheng
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #20926

Type of change

  • Bug fix

What does this PR do?

apply() was calling kv.set("theme_mode", mode) on every THEME_MODE renderer event, persisting the auto-detected value to KV. On the next launch, kv.get("theme_mode") returned this stale value and overrode props.mode (the freshly queried system background color), so the theme stayed stuck on whichever mode was last detected — even if the system had switched.

Two changes:

  1. Remove kv.set("theme_mode", mode) from apply() — auto-detection should never be persisted; only an explicit user lock should be.
  2. Drop the kv.get("theme_mode") fallback in init — on startup, if the user hasn't pinned a lock (theme_mode_lock), use props.mode directly (live system detection from getTerminalBackgroundColor()). This clears any stale KV value left over from the old behavior.

Explicit lock/unlock behavior is unaffected: pin() still writes theme_mode_lock, and lock ?? props.mode in the init correctly picks it up.

How did you verify your code works?

  • bun run typecheck --filter=opencode passes
  • Traced the init path: without a lock, draft.mode = props.mode now comes directly from the terminal background color query — stale KV values can no longer interfere
  • The apply() / renderer event path no longer touches KV at all, so repeated theme events during a session won't overwrite the next session's startup mode

Screenshots / recordings

N/A — internal state fix

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…y render event

apply() was calling kv.set("theme_mode") on every THEME_MODE renderer event,
persisting the auto-detected mode to KV. On the next launch, kv.get("theme_mode")
would return this stale value even if the system theme had changed, overriding
the freshly detected props.mode.

Fix: remove the kv.set from apply() so auto-detection is never persisted.
On init, drop the kv.get("theme_mode") fallback entirely — if the user has an
explicit lock (theme_mode_lock), use it; otherwise use props.mode which is the
live system detection from getTerminalBackgroundColor(). Explicit pin/lock
behavior is unaffected since pin() still writes theme_mode_lock.

Closes anomalyco#20926
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

The following comment was made by an LLM, it may be inaccurate:

The search results show only the current PR (21011) and one related PR from 2024 (15612) that added the initial theme_mode config feature, which is not a duplicate but a related earlier feature.

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no longer respects system theme (macos ghostty)

1 participant