| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
This PR fixes incorrect/stale “Last Activity” relative timestamps by moving dayjs.extend(relativeTime) out of the RepositoryItem component and extracting the logic into a reusable useLastModified hook.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hooks/useLastModified.tsx | New hook for computing “last modified” relative time; initializes dayjs plugin once. |
| components/RepositoryItem.tsx | Uses the new hook instead of defining it inline; removes repeated dayjs.extend. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| import { useEffect, useState } from "react"; | ||
|
|
||
| // Extend dayjs with relativeTime plugin at module scope | ||
| dayjs.extend(relativeTime); | ||
|
|
||
| export const useLastModified = (date: string) => { | ||
| const [lastModified, setLastModified] = useState(""); | ||
|
|
||
| useEffect(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setLastModified(dayjs(date).fromNow()); | ||
| }, [date]); | ||
|
|
||
| return lastModified; |
| useEffect(() => { | ||
| if (isIssueOpen) { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setIsIssuesListVisible(true); | ||
| } else { | ||
| // Delay unmounting to allow close animation to complete | ||
| const timer = setTimeout(() => setIsIssuesListVisible(false), 300); | ||
| const timer = setTimeout(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setIsIssuesListVisible(false); | ||
| }, 300); |
| Back | FazBrowse Home | New Git URL |
Fixes #440
Problem
dayjs.extend(relativeTime) was being called inside the component on every render, causing all repositories to display an incorrect/stale relative timestamp.
Fix
Changes
Note: PR #442 addressed the same issue but has been unreviewed for several months.