[PR #10472] refactor(tui): theme switching & loading reactivity #13456

Open
opened 2026-02-16 18:18:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10472

State: open
Merged: No


Issues

  • Prepares for #6322
    • Shown in GIF below

Refactor

Remodels theme resolution reactivity with respect to this tuple:

  • The user's requested theme
  • The loading status of relevant async resources

This change also prepares for a feature, system-like custom themes, shown in this video:

tui-theme

Fixes

  • Theme picker list now updates on reload
  • Warning toasts on errored
    • These toasts could easily be removed

Performance

The theme context now readies 10x faster (30ms → 3ms) in by-far the most common case: using one of the default themes. The speedup is achieved by not waiting on resources irrelevant to the requested theme before marking it as ready.
Timed using this patch that calls console.time inside createSimpleContext.

After = 3.558ms

...
[17:05:25] [LOG] '%s: %s' 'context:Theme' '3.558ms'
...

Before = 31.264ms

...
[17:04:19] [LOG] '%s: %s' 'context:Theme' '31.264ms'
...

Implementation

  • 2x createResources
    • Custom theme loading
    • System palette detection
  • These in turn are accessed in a createMemo returning this tuple:
    • The user's requested theme
    • The loading status of relevant async resources
  • 2x createEffects
    • One to update the requested theme when the config generation increments
    • Another to promote and re-resolve the theme when our memoized tuple changes
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10472 **State:** open **Merged:** No --- ### Issues - **Prepares for** #6322 - _Shown in GIF below_ ### Refactor Remodels theme resolution reactivity with respect to this tuple: - The user's requested theme - The loading status of relevant async resources This change also prepares for a feature, **system-like custom themes**, shown in this video: <img src="https://github.com/user-attachments/assets/e5384fac-27f9-4a87-9940-783b5c1951d3" alt="tui-theme" width="480" /> ### Fixes - Theme picker list now updates on reload - Warning toasts on errored - These toasts could easily be removed ### Performance The theme context now readies **10x faster** (30ms → 3ms) in by-far the most common case: using one of the default themes. The speedup is achieved by not waiting on resources irrelevant to the requested theme before marking it as ready. _Timed using this [patch](https://github.com/user-attachments/files/24698744/ready-timing.patch) that calls `console.time` inside `createSimpleContext`._ #### After = 3.558ms ``` ... [17:05:25] [LOG] '%s: %s' 'context:Theme' '3.558ms' ... ``` #### Before = 31.264ms ``` ... [17:04:19] [LOG] '%s: %s' 'context:Theme' '31.264ms' ... ``` ### Implementation - 2x `createResource`s - Custom theme loading - System palette detection - These in turn are accessed in a `createMemo` returning this tuple: - The user's requested theme - The loading status of relevant async resources - 2x `createEffect`s - One to update the requested theme when the config generation increments - Another to promote and re-resolve the theme when our memoized tuple changes
yindo added the pull-request label 2026-02-16 18:18:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13456