Skip to content

Conversation

@flegaspi700
Copy link
Owner

No description provided.

Found three locations where saveConversation() was updating timestamps
during conversation loads, causing list to reorder:

1. ✅ saveConversation() itself - added updateTimestamp parameter (PR #23)
2. ✅ handleLoadConversation() - now uses updateTimestamp: false
3. ✅ Auto-save effect - now uses updateTimestamp: false

The auto-save effect was triggering when currentConversationId changed
during load. Even with isLoadingConversationRef flag, the effect would
run and update the timestamp.

Solution:
- Auto-save effect now uses updateTimestamp: false to prevent timestamp
  updates when just preserving state
- Explicit timestamp update added in onComplete callback when user sends
  new messages (the only time we actually want to update the timestamp)

This ensures conversations only move to top when users send new messages,
not when just selecting from history.

Fixes persistent sorting issue confirmed by user.
The root cause was the auto-save effect depending on currentConversationId.
When loading a conversation, setCurrentConversationId() would trigger the
effect, causing an unwanted save that updated the timestamp.

Changes:
1. Removed currentConversationId from effect dependencies
2. Removed "|| currentConversationId" from the if condition (only save when there are messages)
3. Added explicit saveConversation(conversation, true) in onComplete callback to update timestamp when user sends messages
4. Updated comments to explain why currentConversationId is not in dependencies

This ensures the effect only runs when actual content (messages, files, aiTheme) changes,
not when just switching conversations.

Fixes the persistent sorting issue where conversations jump to top when selected.
@flegaspi700 flegaspi700 merged commit d028443 into main Nov 4, 2025
2 checks passed
@flegaspi700 flegaspi700 deleted the fix/auto-save-timestamp-complete branch November 4, 2025 17:53
flegaspi700 added a commit that referenced this pull request Nov 4, 2025
Updated documentation to reflect completed fixes:

1. FUTURE-WORK.md:
   - Moved conversation sorting & title fixes to "Recently Completed"
   - Added technical details and PR references
   - Updated coverage stats (63.29%)

2. conversation-sorting-rearranges-on-selection.md:
   - Added complete resolution section documenting PR #24
   - Explained the three-location bug (saveConversation, handleLoadConversation, auto-save effect)
   - Documented the root cause: auto-save effect dependency on currentConversationId
   - Added solution with code examples

3. conversation-title-not-updating-in-ui.md:
   - Updated status to RESOLVED with PR #22 reference
   - Clarified root cause: component display logic, not state management
   - Added test count (511 tests passing)

4. conversation-title.test.tsx:
   - Changed BUG comment to "Fixed" since issue is resolved

All issues documented as resolved with proper cross-references.
flegaspi700 added a commit that referenced this pull request Nov 4, 2025
Updated documentation to reflect completed fixes:

1. FUTURE-WORK.md:
   - Moved conversation sorting & title fixes to "Recently Completed"
   - Added technical details and PR references
   - Updated coverage stats (63.29%)

2. conversation-sorting-rearranges-on-selection.md:
   - Added complete resolution section documenting PR #24
   - Explained the three-location bug (saveConversation, handleLoadConversation, auto-save effect)
   - Documented the root cause: auto-save effect dependency on currentConversationId
   - Added solution with code examples

3. conversation-title-not-updating-in-ui.md:
   - Updated status to RESOLVED with PR #22 reference
   - Clarified root cause: component display logic, not state management
   - Added test count (511 tests passing)

4. conversation-title.test.tsx:
   - Changed BUG comment to "Fixed" since issue is resolved

All issues documented as resolved with proper cross-references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants