Skip to content

Commit 315134a

Browse files
authored
fix(lifecycle): remove dead q.Style write, keep cache invalidation (#495)
* fix(lifecycle): remove dead q.Style write, keep cache invalidation - Remove dead q.Style assignment in RecursiveGridComponent.UpdateConfig (q.Style was never read - renderer holds its own copy) - Keep SetConfig call to invalidate C caches for theme changes - Reorder calls: modes.UpdateConfig first (updates renderer style), then recursiveGridComponent.UpdateConfig (frees overlay caches) - Eliminates theoretical data race on q.Style during config reload * fix(lifecycle): restore cache-invalidation-before-draw ordering in handleThemeChange * refactor(components): remove stale Style and ThemeProvider fields from RecursiveGridComponent These fields were only set at construction time and read once during renderer initialization. After the first config reload they silently became stale because UpdateConfig no longer rebuilds the Style. All runtime style updates flow through modes.UpdateConfig → renderer.UpdateConfig, so the fields are unnecessary. Remove both fields and build the initial renderer style directly from config at initialization time. * refactor(init): build all overlay styles on-demand from live config Apply the same on-demand style building pattern to hints and grid that was already applied to recursive_grid. This eliminates the architectural inconsistency where two of three components carried a Style field read at renderer init time while the third did not. * docs(lifecycle): fix handleThemeChange comment to match actual call chain
1 parent 972181b commit 315134a

File tree

5 files changed

+19
-44
lines changed

5 files changed

+19
-44
lines changed

internal/app/app_initialization_steps.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,33 +171,17 @@ func initializeSystrayComponent(app *App) {
171171
// initializeRendererAndOverlays sets up the overlay renderer and registers
172172
// all overlays with the overlay manager.
173173
func initializeRendererAndOverlays(app *App) {
174-
// Get styles with nil-safe fallbacks
175-
var hintStyle hints.StyleMode
176-
if app.hintsComponent != nil {
177-
hintStyle = app.hintsComponent.Style
178-
} else {
179-
// Fallback to default style if component is nil
180-
hintStyle = hints.BuildStyle(config.DefaultConfig().Hints)
181-
}
174+
// Build styles directly from config + live theme provider rather than
175+
// reading component fields that would go stale after config reloads.
176+
cfg := config.DefaultConfig()
182177

183-
var gridStyle grid.Style
184-
if app.gridComponent != nil {
185-
gridStyle = app.gridComponent.Style
186-
} else {
187-
// Fallback to default style if component is nil
188-
gridStyle = grid.BuildStyle(config.DefaultConfig().Grid)
178+
if app.config != nil {
179+
cfg = app.config
189180
}
190181

191-
var recursiveGridStyle recursivegrid.Style
192-
if app.recursiveGridComponent != nil {
193-
recursiveGridStyle = app.recursiveGridComponent.Style
194-
} else {
195-
// Fallback to default style if component is nil
196-
recursiveGridStyle = recursivegrid.BuildStyle(
197-
config.DefaultConfig().RecursiveGrid,
198-
defaultThemeProvider,
199-
)
200-
}
182+
hintStyle := hints.BuildStyle(cfg.Hints)
183+
gridStyle := grid.BuildStyle(cfg.Grid)
184+
recursiveGridStyle := recursivegrid.BuildStyle(cfg.RecursiveGrid, defaultThemeProvider)
201185

202186
app.renderer = ui.NewOverlayRenderer(
203187
app.overlayManager,

internal/app/component_factory.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,8 @@ func (f *ComponentFactory) CreateRecursiveGridComponent(
243243
}
244244

245245
return &components.RecursiveGridComponent{
246-
Overlay: recursiveGridOverlay,
247-
Context: &recursivegrid.Context{},
248-
Style: recursivegrid.BuildStyle(f.config.RecursiveGrid, defaultThemeProvider),
249-
ThemeProvider: defaultThemeProvider,
246+
Overlay: recursiveGridOverlay,
247+
Context: &recursivegrid.Context{},
250248
}, nil
251249
}
252250

internal/app/components/types.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,14 @@ func (m *ModeIndicatorComponent) UpdateConfig(cfg *config.Config, _ *zap.Logger)
106106

107107
// RecursiveGridComponent encapsulates all recursive-grid-related functionality.
108108
type RecursiveGridComponent struct {
109-
Manager *domainRecursiveGrid.Manager
110-
Overlay *recursivegrid.Overlay
111-
Context *recursivegrid.Context
112-
Style recursivegrid.Style
113-
ThemeProvider config.ThemeProvider
109+
Manager *domainRecursiveGrid.Manager
110+
Overlay *recursivegrid.Overlay
111+
Context *recursivegrid.Context
114112
}
115113

116114
// UpdateConfig updates the recursive-grid component with new configuration.
117115
func (q *RecursiveGridComponent) UpdateConfig(cfg *config.Config, _ *zap.Logger) {
118-
if cfg.RecursiveGrid.Enabled {
119-
q.Style = recursivegrid.BuildStyle(cfg.RecursiveGrid, q.ThemeProvider)
120-
if q.Overlay != nil {
121-
q.Overlay.SetConfig(cfg.RecursiveGrid)
122-
}
116+
if cfg.RecursiveGrid.Enabled && q.Overlay != nil {
117+
q.Overlay.SetConfig(cfg.RecursiveGrid)
123118
}
124119
}

internal/app/lifecycle.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,14 @@ func (a *App) handleThemeChange(isDark bool) {
543543
return
544544
}
545545

546-
// Re-build styles with the new theme state
546+
// Invalidate the overlay's native C string caches (via SetConfig →
547+
// styleCache.Free + freeLabelCache) so the subsequent draw rebuilds
548+
// them with the new theme-resolved colors.
547549
if a.recursiveGridComponent != nil {
548550
a.recursiveGridComponent.UpdateConfig(cfg, a.logger)
549551
}
550552

553+
// Re-build renderer style with the new theme state, then redraw.
551554
if a.modes != nil {
552555
a.modes.UpdateConfig(cfg)
553556

internal/app/modes/recursive_grid.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ func (h *Handler) initializeRecursiveGridManager(screenBounds image.Rectangle) {
8787
if h.recursiveGrid == nil {
8888
h.recursiveGrid = &components.RecursiveGridComponent{
8989
Context: &componentrecursivegrid.Context{},
90-
Style: componentrecursivegrid.BuildStyle(
91-
h.config.RecursiveGrid,
92-
h.themeProvider,
93-
),
94-
ThemeProvider: h.themeProvider,
9590
}
9691
}
9792

0 commit comments

Comments
 (0)