From bbfc35c58d30212c25c3bf84107456b01856b205 Mon Sep 17 00:00:00 2001 From: Nithin0620 Date: Fri, 8 May 2026 01:37:03 +0530 Subject: [PATCH 1/3] fix: handle GitHub API failure in getRepoStarCount --- apps/web/src/components/topbar.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/topbar.tsx b/apps/web/src/components/topbar.tsx index d688e85d13..1cb26654b5 100644 --- a/apps/web/src/components/topbar.tsx +++ b/apps/web/src/components/topbar.tsx @@ -5,15 +5,26 @@ 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'] }, + }); + + // Return fallback if GitHub API is down or rate-limited + if (!res.ok) return '—'; + + 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 '—'; + + if (starCount > 999) return `${(starCount / 1000).toFixed(1)}K`; + return `${starCount}`; + } catch { + // Network failure or JSON parse error — fail silently + return '—'; } - return `${starCount}`; } export async function Topbar({ From ef00bb86db22d46bf21c49acbb6be3fe3c557763 Mon Sep 17 00:00:00 2001 From: Nithin0620 Date: Fri, 8 May 2026 01:55:11 +0530 Subject: [PATCH 2/3] refactor(topbar): avoid caching fallback API failures --- apps/web/src/components/topbar.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/topbar.tsx b/apps/web/src/components/topbar.tsx index 1cb26654b5..bcc2239576 100644 --- a/apps/web/src/components/topbar.tsx +++ b/apps/web/src/components/topbar.tsx @@ -10,20 +10,23 @@ async function getRepoStarCount() { next: { revalidate: 3600, tags: ['github-repo-stars'] }, }); - // Return fallback if GitHub API is down or rate-limited - if (!res.ok) return '—'; + // 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 '—'; + 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 '—'; + return null; } } @@ -48,7 +51,7 @@ export async function Topbar({ Home - + ); } From a7ca384bc3523427636c23dbb0316b6e955a8e62 Mon Sep 17 00:00:00 2001 From: Nithin0620 Date: Fri, 8 May 2026 01:56:25 +0530 Subject: [PATCH 3/3] refactor(topbar): avoid caching fallback API failures --- apps/web/src/components/topbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/topbar.tsx b/apps/web/src/components/topbar.tsx index bcc2239576..49775cf89f 100644 --- a/apps/web/src/components/topbar.tsx +++ b/apps/web/src/components/topbar.tsx @@ -25,7 +25,7 @@ async function getRepoStarCount() { return `${starCount}`; } catch { - // Network failure or JSON parse error — fail silently + // Network failure or JSON parse error — fail silently return null; } }