diff --git a/apps/web/src/components/topbar.tsx b/apps/web/src/components/topbar.tsx index d688e85d13..49775cf89f 100644 --- a/apps/web/src/components/topbar.tsx +++ b/apps/web/src/components/topbar.tsx @@ -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({ @@ -37,7 +51,7 @@ export async function Topbar({ Home - + ); }