Skip to content

fix: memoize formatRelativeTime in thread list to prevent unnecessary re-renders#1494

Open
okxint wants to merge 1 commit into
MODSetter:devfrom
okxint:fix/memoize-format-relative-time-v2
Open

fix: memoize formatRelativeTime in thread list to prevent unnecessary re-renders#1494
okxint wants to merge 1 commit into
MODSetter:devfrom
okxint:fix/memoize-format-relative-time-v2

Conversation

@okxint

@okxint okxint commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ThreadListItemComponent is wrapped in memo(), but formatRelativeTime(new Date(thread.updatedAt)) was being called inline during render — creating a new Date object and recomputing the formatted string on every parent re-render, even when updatedAt hadn't changed.

This wraps the call in useMemo keyed on thread.updatedAt, so the formatting only runs when the timestamp actually changes.

Changes:

  • Add useMemo to the React import
  • Memoize formatRelativeTime result in ThreadListItemComponent

High-level PR Summary

This PR optimizes the ThreadListItemComponent by memoizing the formatRelativeTime computation to prevent unnecessary re-renders. Previously, the component was creating a new Date object and formatting the timestamp on every parent re-render, even when the updatedAt value hadn't changed. The fix uses useMemo to cache the formatted time string and only recompute it when thread.updatedAt actually changes, improving rendering performance.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/components/assistant-ui/thread-list.tsx

Need help? Join our Discord

… re-renders

ThreadListItemComponent is wrapped in memo(), but formatRelativeTime(new
Date(thread.updatedAt)) was called inline during render, creating a new
Date on every parent re-render regardless of whether updatedAt changed.

Wrap the call in useMemo keyed on thread.updatedAt so the date formatting
only re-runs when the value actually changes.
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@okxint is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79e62bcb-e875-4852-94c1-5cd835a0ce48

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@MODSetter MODSetter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@okxint Thanks but can you resolve merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants