-
Notifications
You must be signed in to change notification settings - Fork 47
Fix/contact message null crash #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix/contact message null crash #21
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a defensive early-return in the chat message renderer for null/invalid message payloads and introduces a localized fallback string for invalid or unsupported messages across all supported languages. Sequence diagram for rendering a chat message with null-guard fallbacksequenceDiagram
actor User
participant ChatUI
participant MessageList
participant MessageContent
participant I18n
User->>ChatUI: OpenConversation(conversationId)
ChatUI->>MessageList: FetchAndRenderMessages(conversationId)
loop For each message
MessageList->>MessageContent: Render(message)
alt message.message is null or undefined
MessageContent->>I18n: t(chat.message.invalidOrUnsupported)
I18n-->>MessageContent: localizedFallbackText
MessageContent-->>MessageList: RenderFallbackDiv(localizedFallbackText)
else message.message is valid
MessageContent-->>MessageList: RenderByMessageType(message.messageType)
end
end
MessageList-->>ChatUI: ConversationDOM
ChatUI-->>User: DisplayConversation()
Flow diagram for MessageContent rendering with null guardflowchart TD
A[Start render MessageContent] --> B{Is message present?}
B -->|No or message is null| C["Call t(chat.message.invalidOrUnsupported)"]
C --> D[Render fallback div with muted styling]
D --> E[End render]
B -->|Yes| F{Is message.message present?}
F -->|No| C
F -->|Yes| G[Read messageType]
G --> H[Switch on messageType and render specific message UI]
H --> E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- The early
if (!message?.message)return inMessageContentchanges behavior for all message types; if the crash only affects contact messages, consider narrowing this guard (e.g. by checkingmessageTypefirst) to avoid hiding other valid-but-empty message contents. - When encountering invalid message payloads, it may be helpful to add some lightweight logging/telemetry (even just
console.warnbehind a dev flag) so malformed messages can be diagnosed rather than only showing a generic fallback in the UI.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The early `if (!message?.message)` return in `MessageContent` changes behavior for all message types; if the crash only affects contact messages, consider narrowing this guard (e.g. by checking `messageType` first) to avoid hiding other valid-but-empty message contents.
- When encountering invalid message payloads, it may be helpful to add some lightweight logging/telemetry (even just `console.warn` behind a dev flag) so malformed messages can be diagnosed rather than only showing a generic fallback in the UI.
## Individual Comments
### Comment 1
<location> `src/pages/instance/Chat/messages.tsx:146` </location>
<code_context>
+ const { t } = useTranslation();
+
+ // Early return for invalid messages
+ if (!message?.message) {
+ return (
+ <div className="text-xs text-muted-foreground bg-muted p-2 rounded max-w-xs">
</code_context>
<issue_to_address>
**issue (bug_risk):** Narrow the invalid-message check to avoid treating valid falsy values as unsupported.
`!message?.message` will mark any falsy value (empty string, `0`, `false`) as invalid/unsupported. If empty strings or other falsy values can be valid, prefer a nullish check like `if (message?.message == null)` or explicitly whitelist the valid values so you don’t misclassify legitimate content as invalid.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Pull Request
📋 Description
This PR fixes a frontend crash in the chat UI caused by malformed or incomplete message payloads coming from the backend.
In production, some messages arrive with
messageset tonull(or missing nested fields), while the UI assumed the presence of properties likecontactMessage, resulting in a runtime error:The fix adds proper null-guards and safe fallbacks when rendering messages, preventing the entire conversation view from breaking.
🔗 Related Issues
Cannot read properties of null (reading 'contactMessage')🧪 Type of Change
🧪 Testing
Test Environment
Test Cases
Test Instructions
📸 Screenshots
Before
Application crashes with:
After
✅ Checklist
Code Quality
npm run lintand fixed blocking issues (warnings only, pre-existing)Testing
Documentation
Internationalization
Breaking Changes
🔄 Migration Guide
Not applicable — no API or behavioral changes for consumers.
📝 Additional Notes
This issue only surfaced in production due to inconsistent message payloads.
The fix ensures the UI is resilient to malformed messages without assuming backend correctness.
🤝 Reviewer Guidelines
Focus Areas
Testing Checklist for Reviewers
Summary by Sourcery
Handle null or malformed chat messages without crashing the conversation view.
Bug Fixes:
Enhancements: