Message Editing & Regeneration - Implementation Progress
Date: 2025-11-23 Status: Phases 1-2 Complete, Phase 3-5 Pending Next Session: Wire up components and complete testing
✅ Completed (This Session)
Phase 1: Enhanced MessageBubble Component
File: apps/web-app/src/components/chat/MessageBubble.tsx
Changes:
- ✅ Added editing state management (
isEditing,editedContent,isSaving) - ✅ Integrated MessageActionMenu component with action callbacks
- ✅ Implemented inline edit UI with textarea
- ✅ Save/cancel handlers with async error handling
- ✅ Keyboard shortcuts: Ctrl/Cmd+Enter (save), Escape (cancel)
- ✅ Updated MessageBubbleProps interface:
onEditSave?: (messageId: string, newContent: string) => Promise<void>onRegenerate?: (messageId: string) => Promise<void>onDelete?: (messageId: string) => Promise<void>
- ✅ Added
groupclass for hover-based action menu visibility
Phase 2: Updated useChatSession Hook
File: apps/web-app/src/hooks/useChatSession.ts
Changes:
- ✅ Imported
useAuthhook to access apiClient - ✅ Added
editingMessageIdstate tracking - ✅ Implemented
editMessage(messageId, newContent):- Calls apiClient.editMessage
- Updates local message state
- Clears editing state on success
- ✅ Implemented
regenerateMessage(messageId):- Finds assistant message and previous user message
- Removes old assistant response
- Re-sends user message via WebSocket
- ✅ Implemented
deleteMessage(messageId):- Confirms with user before deletion
- Calls apiClient.deleteMessage
- Updates local state
- ✅ Updated UseChatSessionReturn interface with new functions
- ✅ All functions properly memoized with useCallback
Additional Fixes
- ✅ Fixed lint errors in
useConversations.ts(removed unusedindexparameters) - ✅ Updated Vitest config to inline ESM modules
📋 Remaining Work
Phase 3: Wire Up Components ⏳
Files to Modify:
apps/web-app/src/pages/ChatPage.tsxapps/web-app/src/components/chat/MessageList.tsx
Tasks:
-
Update ChatPage to destructure new functions from useChatSession:
const { messages, connectionStatus, isTyping, editingMessageId, sendMessage, editMessage, // NEW regenerateMessage, // NEW deleteMessage, // NEW reconnect, } = useChatSession({ conversationId: activeConversationId || "", onError: handleError, initialMessages, }); -
Pass functions to MessageList as props
-
Update MessageList to forward props to MessageBubble:
<MessageBubble message={message} isStreaming={isStreaming && index === messages.length - 1} onEditSave={onEditSave} onRegenerate={onRegenerate} onDelete={onDelete} />
Phase 4: Comprehensive Tests ⏳
Files to Create:
4.1 MessageActionMenu Tests
File: apps/web-app/src/components/chat/__tests__/MessageActionMenu.test.tsx
Test Cases (6 minimum):
- Renders menu button
- Shows edit option for user messages only
- Shows regenerate option for assistant messages only
- Does not render for system messages
- Calls onEdit when edit is clicked
- Closes menu after action
4.2 useChatSession Editing Tests
File: apps/web-app/src/hooks/__tests__/useChatSession-editing.test.ts
Test Cases (4 minimum):
- Should edit a message successfully
- Should delete a message successfully
- Should regenerate assistant message
- Should handle edit errors gracefully
4.3 MessageBubble Editing Tests
File: apps/web-app/src/components/chat/__tests__/MessageBubble-editing.test.tsx
Test Cases (6 minimum):
- Shows edit button on hover for user messages
- Enters edit mode when edit is clicked
- Saves edited message when save is clicked
- Cancels edit when cancel is clicked
- Saves on Ctrl+Enter keyboard shortcut
- Cancels on Escape keyboard shortcut
Phase 5: Polish & Accessibility ⏳
Tasks:
- Add loading states during save operations
- Add error toast notifications (integrate with toast system)
- Test keyboard navigation through action menu
- Test with screen reader (NVDA/JAWS)
- Verify ARIA attributes are correct
- Update component documentation with examples
- Update
FRONTEND_PHASE1_PHASE2_SUMMARY.md
⚠️ Known Issues
Test Environment - ESM Import Issues
Issue: 4 test suites failing with ESM import errors for react-syntax-highlighter
Error: require() of ES Module ... refractor@5.0.0 ... not supported
Affected Tests:
src/__tests__/AppSmoke.test.tsxsrc/__tests__/integration/ChatFlow.test.tsxsrc/components/chat/__tests__/MessageBubble.test.tsxsrc/components/chat/__tests__/MessageList.test.tsx
Additional Failures: 4 tests in useChatSession.test.ts (timeout/mock issues - pre-existing)
Attempted Fixes:
- ✅ Added ESM modules to
deps.inlinein vitest.config.mts - ✅ Created mock file at
src/__mocks__/react-syntax-highlighter.ts - ✅ Added alias in vitest.config.mts resolve section
- ❌ Tests still failing (mock not being used correctly)
Root Cause: react-syntax-highlighter imports ESM-only refractor package via CommonJS, causing incompatibility in Vitest's test environment.
Impact:
- Production: ✅ NO IMPACT - Code works fine in browser
- Development: ⚠️ 4 test suites cannot run (118/122 passing tests unaffected)
- Phase 1-2: ✅ Implementations complete and committed (8cf91f0)
Recommendation: Proceed with Phase 3 (component wiring) since this is a pre-existing test infrastructure issue unrelated to the message editing feature. The failing tests are smoke tests and integration tests that will need to be fixed separately as part of test infrastructure maintenance.
Future Fix Options:
- Replace
react-syntax-highlighterwith a different syntax highlighting library - Lazy-load syntax highlighter only when needed (code blocks present)
- Configure Vitest to use Vite's SSR mode for better ESM support
- Wait for
react-syntax-highlighterto release CommonJS-compatible version
📝 Implementation Notes
API Integration
- Edit/delete operations call REST API via apiClient
- Regenerate operation uses existing WebSocket streaming
- All operations update local state optimistically after server response
State Management
- Editing state managed in MessageBubble component (local)
- Message updates flow through useChatSession hook
- WebSocket connection maintained throughout editing
User Experience
- Inline editing with textarea (no modal)
- Keyboard shortcuts for power users
- Confirmation dialog for destructive actions (delete)
- Save button disabled during async operations
- Original content restored on cancel
🚀 Next Session Plan
-
Fix Test Environment (30 min)
- Investigate and resolve ESM import issues
- Ensure all existing tests pass
- Run
pnpm testto verify baseline
-
Phase 3: Wire Up Components (60 min)
- Update ChatPage.tsx
- Update MessageList.tsx
- Manual testing in browser
-
Phase 4: Write Tests (90 min)
- MessageActionMenu tests (6 tests)
- useChatSession editing tests (4 tests)
- MessageBubble editing tests (6 tests)
- Run full suite and fix failures
-
Phase 5: Polish (45 min)
- Loading states and error handling
- Accessibility audit
- Documentation updates
-
Final Verification (30 min)
make test(backend)pnpm lint(should pass with warnings only)pnpm test(all tests green)- Manual E2E testing
-
Commit & Push (15 min)
- Clear commit message
- Update CHANGELOG if applicable
- Push to origin/main
Estimated Total: 4-5 hours
📚 Reference Documents
- Full specification:
docs/REMAINING_MESSAGE_EDIT_WORK.md - Feature specs:
docs/client-implementation/WEB_APP_FEATURE_SPECS.md - Phase summary:
docs/client-implementation/FRONTEND_PHASE1_PHASE2_SUMMARY.md
Last Updated: 2025-11-23 Next Update: After Phase 3 completion