fix: prevent null reference reading 'error' in MessagesBoundary#1284
fix: prevent null reference reading 'error' in MessagesBoundary#1284wsolarq11 wants to merge 1 commit into
Conversation
normalizeMessages and toSDKMessages access message.error in flatMap callbacks executed during React render (via useMemo). When a null element is present in the messages array at runtime (e.g., from corrupted JSONL deserialization or streaming race conditions), null.error throws "Cannot read properties of null (reading 'error')". Add null guards to flatMap/forEach callbacks and optional chaining on message.error access points in normalizeMessages and toSDKMessages. Fixes: React Rendering Error in MessagesBoundary Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds falsy-entry guards ( ChangesNull Guards for Message Array Entries
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
MessagesBoundarynormalizeMessagesprocesses a message array containing null elementsRoot Cause
normalizeMessagesis called insideuseMemoatsrc/components/Messages.tsx:410, which executes synchronously during React render phase. When the messages array contains a null element (possible via JSONL deserialization, streaming race conditions, or compact/merge operations),flatMappasses it to the callback wheremessage.erroris accessed →null.error→TypeError: Cannot read properties of null (reading 'error').Changes
src/utils/messages.ts:756if (!message) return []null guard innormalizeMessagesflatMapsrc/utils/messages.ts:781error: message.error→error: message?.errorsrc/utils/messages.ts:2380if (!message) return []null guard innormalizeMessagesForAPIforEachsrc/utils/messages/mappers.ts:32if (!message) return []null guard intoInternalMessagesflatMapsrc/utils/messages/mappers.ts:131if (!message) return []null guard infromSDKCompactMetadataflatMapsrc/utils/messages/mappers.ts:143error: message.error→error: message?.errorVerification
🤖 Generated with Claude Code Best
Summary by CodeRabbit