Skip to content

fix: guard against missing ts in lastMessage on Channel Directory#40519

Open
SiddhiPandey08 wants to merge 1 commit into
RocketChat:developfrom
SiddhiPandey08:fix/channel-directory-crash-missing-ts
Open

fix: guard against missing ts in lastMessage on Channel Directory#40519
SiddhiPandey08 wants to merge 1 commit into
RocketChat:developfrom
SiddhiPandey08:fix/channel-directory-crash-missing-ts

Conversation

@SiddhiPandey08
Copy link
Copy Markdown

@SiddhiPandey08 SiddhiPandey08 commented May 14, 2026

Proposed changes (including videos or screenshots)

The Channel Directory was crashing with RangeError: Invalid time value
when a channel's lastMessage contained a reactions object but no ts field.

Fixed by adding optional chaining on lastMessage.ts before calling
formatDate in ChannelsTableRow.tsx line 50.

Before: {lastMessage && formatDate(lastMessage.ts)}
After: {lastMessage?.ts && formatDate(lastMessage.ts)}

Issue(s)

Closes #40503

Steps to test or reproduce

  1. Go to Workspace Settings and disable "Save Last Message"
  2. Create a new channel
  3. Send a message to that channel
  4. Re-enable "Save Last Message"
  5. Add a reaction to the message sent in step 3
  6. Navigate to /directory/channels
  7. Before fix: app crashes. After fix: directory loads normally

Further comments

Summary by CodeRabbit

  • Refactor
    • Improved robustness of timestamp handling in the channels table to better handle edge cases where timestamp data may not be available.

Review Change Stack

Copilot AI review requested due to automatic review settings May 14, 2026 02:31
@SiddhiPandey08 SiddhiPandey08 requested a review from a team as a code owner May 14, 2026 02:31
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented May 14, 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 14, 2026

⚠️ No Changeset found

Latest commit: 3a122e0

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

CLAassistant commented May 14, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78af3c2c-4123-4027-acaa-cf477cdf1941

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae9ab0 and 3a122e0.

📒 Files selected for processing (1)
  • apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
🔇 Additional comments (1)
apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx (1)

50-50: LGTM!


Walkthrough

ChannelsTableRow now validates that lastMessage?.ts exists before formatting the timestamp, replacing a check that only verified lastMessage truthiness. This defensive change prevents crashes when a channel's lastMessage object lacks a timestamp field.

Changes

Timestamp Safety in Directory

Layer / File(s) Summary
Timestamp safety check in ChannelsTableRow
apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx
The conditional rendering for the last message date now uses optional chaining on lastMessage?.ts instead of checking only lastMessage, ensuring formatDate is only called when a timestamp exists.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: adding defensive guards for missing ts in lastMessage on the Channel Directory component.
Linked Issues check ✅ Passed The PR successfully addresses issue #40503 by adding optional chaining for lastMessage.ts to prevent RangeError when ts field is missing, allowing the directory to load normally.
Out of Scope Changes check ✅ Passed The PR contains only a single focused change to ChannelsTableRow.tsx that directly addresses the linked issue; no out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a UI crash in the Channel Directory caused by attempting to format a missing lastMessage.ts timestamp when lastMessage contains reactions but no ts.

Changes:

  • Adds a guard before calling formatDate for the “Last Message” column in the channels directory table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{mediaQuery && (
<GenericTableCell fontScale='p2' color='hint' withTruncatedText>
{lastMessage && formatDate(lastMessage.ts)}
{lastMessage?.ts && formatDate(lastMessage.ts)}
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

3 participants