diff --git a/src/components/MentalHealthChatDemo.tsx b/src/components/MentalHealthChatDemo.tsx index 6f6e37757..00e1f148e 100644 --- a/src/components/MentalHealthChatDemo.tsx +++ b/src/components/MentalHealthChatDemo.tsx @@ -382,6 +382,13 @@ How are you feeling today? I'm here to listen and help.`, .map((m) => m.mentalHealthAnalysis!) }, [messages]) + // ⚡ Bolt: Memoize filtered analyzed user messages to prevent O(N) re-filtering on every render + const analyzedUserMessages = useMemo(() => { + return messages.filter( + (m) => m.role === 'user' && m.mentalHealthAnalysis && !m.isProcessing, + ) + }, [messages]) + // Enhanced analysis for component compatibility const enhancedAnalysisHistory = useMemo(() => { const analysisHistory = getAnalysisHistory() @@ -1130,13 +1137,7 @@ It sounds like you're dealing with some challenges. What's been the most difficu
- {messages - .filter( - (m) => - m.role === 'user' && - m.mentalHealthAnalysis && - !m.isProcessing, - ) + {analyzedUserMessages .slice(-2) .map((m) => (