From 5366d4b9aea369e9befff8a13a4a0f5be6138645 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Tue, 14 Apr 2026 19:59:36 +0200 Subject: [PATCH] fix: replace invalid top-level return with isFresh flag in star scripts Top-level return is a syntax error in ES modules. Replace the early return pattern with an isFresh boolean guard. Also revert the hero "Star on GitHub" button change. --- site/src/components/Header.astro | 5 +++-- site/src/components/StatsBar.astro | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/site/src/components/Header.astro b/site/src/components/Header.astro index 0c657d9..436b7cf 100644 --- a/site/src/components/Header.astro +++ b/site/src/components/Header.astro @@ -173,15 +173,16 @@ const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(star } const cached = sessionStorage.getItem(CACHE_KEY); + let isFresh = false; if (cached) { const { value, ts } = JSON.parse(cached); if (Date.now() - ts < CACHE_TTL) { starsEl.textContent = formatStars(value); - return; // cache is fresh, skip API call + isFresh = true; } } - fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', { + if (!isFresh) fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', { headers: { Accept: 'application/vnd.github+json' }, }) .then((r) => r.ok ? r.json() : null) diff --git a/site/src/components/StatsBar.astro b/site/src/components/StatsBar.astro index eef3c02..9867d98 100644 --- a/site/src/components/StatsBar.astro +++ b/site/src/components/StatsBar.astro @@ -55,15 +55,16 @@ const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(star } const cached = sessionStorage.getItem(CACHE_KEY); + let isFresh = false; if (cached) { const { value, ts } = JSON.parse(cached); if (Date.now() - ts < CACHE_TTL) { starsEl.textContent = fmt(value); - return; // cache is fresh, skip API call + isFresh = true; } } - fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', { + if (!isFresh) fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', { headers: { Accept: 'application/vnd.github+json' }, }) .then((r) => r.ok ? r.json() : null)