Commit d2cce73
authored
Feat/save empty conversations (#21)
* fix: resolve TypeScript error in theme-provider test
- Fix 'children' prop missing error by passing undefined instead of empty
- All 11 tests still passing
- Resolves TypeScript compilation error
* test: add tests for empty conversation saving (TDD Red)
TDD Red Phase - Failing tests:
- conversation-title: Edit button should show for new conversations
- page: Should allow editing title without messages
- page: Should save empty conversation when title is changed
These tests expect:
1. Edit button visible on new/empty conversations
2. Title editable before sending first message
3. Conversation saved when title is edited (even with no messages)
Tests currently failing - implementation to follow
* feat: allow saving and editing empty conversations (TDD Green)
TDD Green Phase - Implementation:
- Remove edit button conditional in conversation-title.tsx
- Create conversation ID when title changes on empty conversation
- Save empty conversations to localStorage
- Update auto-save to support conversations without messages
Features:
- Edit button now visible on new conversations
- Title can be changed before sending first message
- Conversations persist even with no messages/files
Testing:
- Updated conversation-title.test.tsx selector to be more specific
- Updated page.test.tsx to check localStorage directly
- All 508 tests passing
* fix: ensure conversation title updates in header when changed
Issue: Title was saving to localStorage but not updating in the header
Root cause: Auto-save useEffect was calling createConversation without
passing the conversationTitle parameter, causing it to overwrite the
user's title with an auto-generated one.
Solution: Pass conversationTitle to createConversation when updating
an existing conversation, ensuring the user's custom title is preserved
in both storage and the UI.
All tests passing.
* fix: remove conversationTitle from auto-save dependencies
Issue: Title would revert to 'New Conversation' after being changed,
even though it saved correctly in localStorage/history.
Root Cause: conversationTitle was in the auto-save useEffect dependency
array, causing it to re-run every time the title changed. This triggered
the auto-save logic which would sometimes overwrite the user's custom
title with an auto-generated one.
Solution: Remove conversationTitle from dependencies since title updates
are already handled by handleTitleChange and updateConversationTitle.
The auto-save should only trigger on content changes (messages, files,
aiTheme), not title changes.
All tests passing.
* fix: use ref to track conversation title and prevent stale closure
Issue: Title would update in localStorage but revert to 'New Conversation'
in the header after being changed.
Root Cause: The auto-save useEffect was using a stale conversationTitle
value from closure. Since conversationTitle was removed from dependencies
to prevent infinite loops, the effect closure captured the old value and
kept using 'New Conversation' instead of the updated title.
Solution: Introduce conversationTitleRef to track the current title value.
This ref is updated immediately when the title changes and is always
current when the auto-save effect runs. The ref bypasses React's batching
and closure staleness issues.
Changes:
- Added conversationTitleRef to track current title
- Update ref in all places where setConversationTitle is called
- Auto-save effect now uses conversationTitleRef.current for latest value
- handleTitleChange also saves full conversation to ensure sync
All tests passing (17 passed, 13 skipped).
* fix: update title ref before setting conversation ID to prevent race condition
Issue: When loading a conversation from history, the title would not
update in the header (e.g., loading 'Test 5' would still show 'New
Conversation').
Root Cause: In handleLoadConversation, conversationTitleRef was being
updated AFTER setCurrentConversationId. This caused the auto-save effect
(triggered by the ID change) to run with the old/stale ref value before
the ref was updated with the new title.
Solution: Update the title and ref BEFORE setting the conversation ID.
This ensures conversationTitleRef.current has the correct value when
the auto-save effect runs.
Order of operations now:
1. Set title state and ref (with new title)
2. Set conversation ID (triggers auto-save)
3. Auto-save uses the already-updated ref value
All tests passing.
* refactor: auto-sync conversationTitle ref with state using useEffect
Simplification: Instead of manually updating conversationTitleRef.current
in multiple places, use a useEffect to automatically keep the ref in sync
with the conversationTitle state. This ensures the ref is always current
and reduces code duplication.
Benefits:
- Single source of truth for title updates
- Eliminates manual ref assignments scattered throughout the code
- Prevents missing ref updates when title state changes
- Cleaner and more maintainable code
The useEffect runs whenever conversationTitle changes, ensuring
conversationTitleRef.current is always up-to-date when the auto-save
effect needs it.
All tests passing (17 passed, 13 skipped).
* docs: add issue documentation for conversation title UI update bug
Issue: Title updates in localStorage and sidebar but not in header until
page refresh. Documented attempted fixes, suspected root causes, and
possible solutions for future debugging.
Status: Open - requires further investigation1 parent f77a050 commit d2cce73
File tree
5 files changed
+265
-37
lines changed- docs/04-development/issues
- src
- __tests__
- app
- components
- app
- components
5 files changed
+265
-37
lines changedLines changed: 160 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
403 | 445 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
128 | 138 | | |
129 | | - | |
130 | | - | |
131 | 139 | | |
132 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
133 | 143 | | |
134 | 144 | | |
135 | 145 | | |
| |||
174 | 184 | | |
175 | 185 | | |
176 | 186 | | |
| 187 | + | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
179 | | - | |
180 | 191 | | |
181 | 192 | | |
182 | 193 | | |
| |||
187 | 198 | | |
188 | 199 | | |
189 | 200 | | |
190 | | - | |
191 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
192 | 214 | | |
193 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
194 | 221 | | |
195 | 222 | | |
196 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
| |||
0 commit comments