Skip to content

fix: prevent UI crash in channel directory when lastMessage timestamp is missing#40584

Open
ujjwalkar0 wants to merge 3 commits into
RocketChat:developfrom
ujjwalkar0:fix/channel-directory-ui-crash-missing-timestamp
Open

fix: prevent UI crash in channel directory when lastMessage timestamp is missing#40584
ujjwalkar0 wants to merge 3 commits into
RocketChat:developfrom
ujjwalkar0:fix/channel-directory-ui-crash-missing-timestamp

Conversation

@ujjwalkar0
Copy link
Copy Markdown

@ujjwalkar0 ujjwalkar0 commented May 16, 2026

Summary

Fixes a critical bug where the Channel Directory crashes the entire UI with RangeError: Invalid time value when a channel's lastMessage contains reactions but lacks a timestamp.

Root Cause

When the Store Last Message setting is disabled and re-enabled, messages sent while it was disabled may have a lastMessage object with reactions data but no ts (timestamp) field. The code attempted to format this undefined timestamp using formatDate(), 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.tsx

Problem:

// Before - crashes when lastMessage.ts is undefined
{mediaQuery && (
  <GenericTableCell fontScale='p2' color='hint' withTruncatedText>
    {lastMessage && formatDate(lastMessage.ts)}
  </GenericTableCell>
)}

Solution:

// After - safely checks for timestamp existence
const lastMessageTs = lastMessage?.ts;

{mediaQuery && lastMessageTs && (
  <GenericTableCell fontScale='p2' color='hint' withTruncatedText>
    {formatDate(lastMessageTs)}
  </GenericTableCell>
)}

The fix extracts lastMessage?.ts to a variable for proper TypeScript type narrowing under strictNullChecks, then only calls formatDate() when the timestamp actually exists.

How to Reproduce the Bug

  1. Go to Administration → Settings → General
  2. Disable "Store Last Message" setting
  3. Create a new channel (to ensure no last message is stored)
  4. Send a message to the new channel
  5. Go back to settings and re-enable "Store Last Message"
  6. Add a reaction (emoji) to the message you sent in step 4
  7. Navigate to /directory/channels

Expected 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:

  • "Application Error" screen
  • Browser console: Uncaught RangeError: Invalid time value
  • Stack trace points to ChannelsTableRow.tsx:50

After 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

  • Verified channel directory loads without crashing
  • Tested with channels that have messages with reactions but no timestamp
  • Tested with channels that have normal messages with timestamps
  • Verified TypeScript compilation passes with strictNullChecks
  • No console errors in browser
image

Automated Testing

  • Unit test added (if applicable)
  • E2E test added (if applicable)

Checklist

  • Code follows project guidelines
  • Self-review of changes completed
  • Changes tested manually
  • TypeScript compilation passes
  • E2E tests added/updated (if applicable)
  • Documentation updated (if needed)

For Maintainers

  • Please add label: stat: QA tested
  • Please set appropriate milestone
  • Ready for review

Impact: 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

  • Bug Fixes
    • Improved timestamp display accuracy in the channels table by correctly deriving and rendering the last message timestamp.

Review Change Stack

… 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
@ujjwalkar0 ujjwalkar0 requested a review from a team as a code owner May 16, 2026 15:22
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented May 16, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 16, 2026

⚠️ No Changeset found

Latest commit: a8e6988

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Walkthrough

The PR fixes timestamp rendering in ChannelsTableRow by deriving lastMessageTs from lastMessage?.ts and using it for conditional display. The timestamp cell now only renders when both the media-query condition and lastMessageTs are truthy, addressing null reference issues with the previous room-based timestamp logic.

Changes

Timestamp rendering from lastMessage

Layer / File(s) Summary
Timestamp derivation and conditional rendering
apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
Extracts lastMessageTs from lastMessage?.ts and updates the timestamp cell rendering to conditionally display only when both mediaQuery and lastMessageTs are truthy, formatting lastMessageTs directly.

Possibly related issues

  • #40503: The change fixes timestamp rendering by deriving from lastMessage?.ts instead of unconditionally using room ts, directly addressing crashes when lastMessage lacks a timestamp.

Suggested labels

type: bug


🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: fixing a UI crash in the channel directory caused by missing lastMessage timestamp.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@ujjwalkar0 ujjwalkar0 changed the title fix: prevent UI crash in channel directory when lastMessage timestamp… fix: prevent UI crash in channel directory when lastMessage timestamp May 16, 2026
@ujjwalkar0 ujjwalkar0 changed the title fix: prevent UI crash in channel directory when lastMessage timestamp fix: prevent UI crash in channel directory when lastMessage timestamp is missing May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI Crash (RangeError) in Channel Directory when lastMessage has reactions but missing timestamp

2 participants