BubbleTea Code Review
Quick Reference
| Issue Type |
Reference |
| Elm architecture, tea.Cmd as data |
references/elm-architecture.md |
| Model state, message handling |
references/model-update.md |
| View rendering, Lipgloss styling |
references/view-styling.md |
| Component composition, Huh forms |
references/composition.md |
| Bubbles components (list, table, etc.) |
references/bubbles-components.md |
CRITICAL: Avoid False Positives
Read elm-architecture.md first! The most common review mistake is flagging correct patterns as bugs.
NOT Issues (Do NOT Flag These)
| Pattern |
Why It's Correct |
return m, m.loadData() |
tea.Cmd is returned immediately; runtime executes async |
Value receiver on Update() |
Standard BubbleTea pattern; model returned by value |
Nested m.child, cmd = m.child.Update(msg) |
Normal component composition |
Helper functions returning tea.Cmd |
Creates command descriptor, no I/O in Update |
tea.Batch(cmd1, cmd2) |
Commands execute concurrently by runtime |
ACTUAL Issues (DO Flag These)
| Pattern |
Why It's Wrong |
os.ReadFile() in Update |
Blocks UI thread |
http.Get() in Update |
Network I/O blocks |
time.Sleep() in Update |
Freezes UI |
<-channel in Update (blocking) |
May block indefinitely |
huh.Form.Run() in Update |
Blocking call |
Review Checklist
Architecture
Model & Update
View & Styling
Components
Critical Patterns
Model Must Be Immutable
// BAD - mutates model
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.items = append(m.items, newItem) // mutation!
return m, nil
}
// GOOD - returns new model
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
newItems := make([]Item, len(m.items)+1)
copy(newItems, m.items)
newItems[len(m.items)] = newItem
m.items = newItems
return m, nil
}
Commands for Async/IO
// BAD - blocking in Update
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
data, _ := os.ReadFile("config.json") // blocks UI!
m.config = parse(data)
return m, nil
}
// GOOD - use commands
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, loadConfigCmd()
}
func loadConfigCmd() tea.Cmd {
return func() tea.Msg {
data, err := os.ReadFile("config.json")
if err != nil {
return errMsg{err}
}
return configLoadedMsg{parse(data)}
}
}
Styles Defined Once
// BAD - creates new style each render
func (m Model) View() string {
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
return style.Render("Hello")
}
// GOOD - define styles at package level or in model
var titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
func (m Model) View() string {
return titleStyle.Render("Hello")
}
When to Load References
- First time reviewing BubbleTea → elm-architecture.md (prevents false positives)
- Reviewing Update function logic → model-update.md
- Reviewing View function, styling → view-styling.md
- Reviewing component hierarchy → composition.md
- Using Bubbles components → bubbles-components.md
Review Questions
- Is Update() free of blocking I/O? (NOT: "is the cmd helper blocking?")
- Is the model immutable in Update?
- Are Lipgloss styles defined once, not in View?
- Is WindowSizeMsg handled for resizing?
- Are key bindings documented with help.KeyMap?
- Are Bubbles components sized correctly?
1---2name: bubbletea-code-review3description: Reviews BubbleTea TUI code for proper Elm architecture, model/update/view patterns, and Lipgloss styling. Use when reviewing terminal UI code using charmbracelet/bubbletea.4---5
6# BubbleTea Code Review
7
8## Quick Reference
9
10| Issue Type | Reference |
11|------------|-----------|
12| Elm architecture, tea.Cmd as data | [references/elm-architecture.md](references/elm-architecture.md) |
13| Model state, message handling | [references/model-update.md](references/model-update.md) |
14| View rendering, Lipgloss styling | [references/view-styling.md](references/view-styling.md) |
15| Component composition, Huh forms | [references/composition.md](references/composition.md) |
16| Bubbles components (list, table, etc.) | [references/bubbles-components.md](references/bubbles-components.md) |
17
18## CRITICAL: Avoid False Positives
19
20**Read [elm-architecture.md](references/elm-architecture.md) first!** The most common review mistake is flagging correct patterns as bugs.
21
22### NOT Issues (Do NOT Flag These)
23
24| Pattern | Why It's Correct |
25|---------|------------------|
26| `return m, m.loadData()` | `tea.Cmd` is returned immediately; runtime executes async |
27| Value receiver on `Update()` | Standard BubbleTea pattern; model returned by value |
28| Nested `m.child, cmd = m.child.Update(msg)` | Normal component composition |
29| Helper functions returning `tea.Cmd` | Creates command descriptor, no I/O in Update |
30| `tea.Batch(cmd1, cmd2)` | Commands execute concurrently by runtime |
31
32### ACTUAL Issues (DO Flag These)
33
34| Pattern | Why It's Wrong |
35|---------|----------------|
36| `os.ReadFile()` in Update | Blocks UI thread |
37| `http.Get()` in Update | Network I/O blocks |
38| `time.Sleep()` in Update | Freezes UI |
39| `<-channel` in Update (blocking) | May block indefinitely |
40| `huh.Form.Run()` in Update | Blocking call |
41
42## Review Checklist
43
44### Architecture
45- [ ] **No blocking I/O in Update()** (file, network, sleep)
46- [ ] Helper functions returning `tea.Cmd` are NOT flagged as blocking
47- [ ] Commands used for all async operations
48
49### Model & Update
50- [ ] Model is immutable (Update returns new model, not mutates)
51- [ ] Init returns proper initial command (or nil)
52- [ ] Update handles all expected message types
53- [ ] WindowSizeMsg handled for responsive layout
54- [ ] tea.Batch used for multiple commands
55- [ ] tea.Quit used correctly for exit
56
57### View & Styling
58- [ ] View is a pure function (no side effects)
59- [ ] Lipgloss styles defined once, not in View
60- [ ] Key bindings use key.Matches with help.KeyMap
61
62### Components
63- [ ] Sub-component updates propagated correctly
64- [ ] Bubbles components initialized with dimensions
65- [ ] Huh forms embedded via Update loop (not Run())
66
67## Critical Patterns
68
69### Model Must Be Immutable
70
71```go
72// BAD - mutates model
73func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
74 m.items = append(m.items, newItem) // mutation!
75 return m, nil
76}
77
78// GOOD - returns new model
79func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
80 newItems := make([]Item, len(m.items)+1)
81 copy(newItems, m.items)
82 newItems[len(m.items)] = newItem
83 m.items = newItems
84 return m, nil
85}
86```
87
88### Commands for Async/IO
89
90```go
91// BAD - blocking in Update
92func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
93 data, _ := os.ReadFile("config.json") // blocks UI!
94 m.config = parse(data)
95 return m, nil
96}
97
98// GOOD - use commands
99func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
100 return m, loadConfigCmd()
101}
102
103func loadConfigCmd() tea.Cmd {
104 return func() tea.Msg {
105 data, err := os.ReadFile("config.json")
106 if err != nil {
107 return errMsg{err}
108 }
109 return configLoadedMsg{parse(data)}
110 }
111}
112```
113
114### Styles Defined Once
115
116```go
117// BAD - creates new style each render
118func (m Model) View() string {
119 style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
120 return style.Render("Hello")
121}
122
123// GOOD - define styles at package level or in model
124var titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
125
126func (m Model) View() string {
127 return titleStyle.Render("Hello")
128}
129```
130
131## When to Load References
132
133- **First time reviewing BubbleTea** → [elm-architecture.md](references/elm-architecture.md) (prevents false positives)
134- Reviewing Update function logic → [model-update.md](references/model-update.md)
135- Reviewing View function, styling → [view-styling.md](references/view-styling.md)
136- Reviewing component hierarchy → [composition.md](references/composition.md)
137- Using Bubbles components → [bubbles-components.md](references/bubbles-components.md)
138
139## Review Questions
140
1411. Is Update() free of blocking I/O? (NOT: "is the cmd helper blocking?")
1422. Is the model immutable in Update?
1433. Are Lipgloss styles defined once, not in View?
1444. Is WindowSizeMsg handled for resizing?
1455. Are key bindings documented with help.KeyMap?
1466. Are Bubbles components sized correctly?