Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions apps/web/src/components/topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ import { Logo } from './logo';
import { Menu } from './menu';

async function getRepoStarCount() {
const res = await fetch('https://api.github.com/repos/resend/react-email', {
next: { revalidate: 3600, tags: ['github-repo-stars'] },
});
const data = await res.json();
const starCount = data.stargazers_count as number;
if (starCount > 999) {
return `${(starCount / 1000).toFixed(1)}K`;
try {
const res = await fetch('https://api.github.com/repos/resend/react-email', {
next: { revalidate: 3600, tags: ['github-repo-stars'] },
});

// Avoid caching transient GitHub failures as valid fallback data
if (!res.ok) return null;

const data = await res.json();
const starCount = data.stargazers_count as number;

// Guard against undefined/NaN if API response shape changes
if (typeof starCount !== 'number' || Number.isNaN(starCount)) {
return null;
}

if (starCount > 999) return `${(starCount / 1000).toFixed(1)}K`;

return `${starCount}`;
} catch {
// Network failure or JSON parse error — fail silently
return null;
}
return `${starCount}`;
}

export async function Topbar({
Expand All @@ -37,7 +51,7 @@ export async function Topbar({
<Logo />
<span className="sr-only">Home</span>
</Link>
<Menu starCount={starCount} />
<Menu starCount={starCount ?? '—'} />
</header>
);
}
Loading