fix: prevent UI crash in channel directory when lastMessage timestamp is missing#40584
Conversation
… is missing - Add null check for lastMessage.ts before formatting date - Extract lastMessage?.ts to a variable for proper TypeScript type narrowing - Prevents RangeError when lastMessage has reactions but no timestamp Fixes issue where disabling/enabling 'Store Last Message' setting causes channel directory to crash with 'Invalid time value' error
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
|
WalkthroughThe PR fixes timestamp rendering in ChangesTimestamp rendering from lastMessage
Possibly related issues
Suggested labels
🎯 2 (Simple) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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
Fixes a critical bug where the Channel Directory crashes the entire UI with
RangeError: Invalid time valuewhen a channel'slastMessagecontains reactions but lacks a timestamp.Root Cause
When the
Store Last Messagesetting is disabled and re-enabled, messages sent while it was disabled may have alastMessageobject withreactionsdata but nots(timestamp) field. The code attempted to format this undefined timestamp usingformatDate(), causing the entire React application to crash with an "Application Error" screen.Technical Details
File Changed:
apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsxProblem:
Solution:
The fix extracts
lastMessage?.tsto a variable for proper TypeScript type narrowing understrictNullChecks, then only callsformatDate()when the timestamp actually exists.How to Reproduce the Bug
/directory/channelsExpected Behavior
The directory should load normally. If a timestamp is missing, the "Last Message" column should be empty or show a placeholder.
Actual Behavior (Before Fix)
The application crashes with:
Uncaught RangeError: Invalid time valueChannelsTableRow.tsx:50After Fix
✅ Directory loads successfully without crashing
✅ Empty cell displayed when timestamp is missing
✅ No breaking changes to existing functionality
Related Issue
Fixes #40503
Testing
Manual Testing
strictNullChecksAutomated Testing
Checklist
For Maintainers
stat: QA testedImpact: This fix prevents a critical UI crash that makes the channel directory completely unusable for users encountering this edge case.
Risk Level: Low - Only adds a null check, no behavioral changes to existing functionality.
Summary by CodeRabbit