Skip to content

fix(site): live GitHub star count on the landing page (client-side, no build-time fetch)#153

Merged
onsails merged 2 commits into
masterfrom
fix/live-github-star-count
Jul 8, 2026
Merged

fix(site): live GitHub star count on the landing page (client-side, no build-time fetch)#153
onsails merged 2 commits into
masterfrom
fix/live-github-star-count

Conversation

@onsails

@onsails onsails commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Problem

The landing page showed 26 GitHub stars while the repo was already at 30.

Not a code bug — the count was fetched at build time (getStars() in site/src/lib/github.ts) and baked into the static HTML. The Pages deploy (.github/workflows/static.yml) only runs on site/** changes or manual dispatch, so the number drifted behind reality between deploys. Two badges were affected: the hero button (.starbtn .cnt) and the nav chip (.starchip).

Fix

Fetch the count client-side and drop the build-time API call entirely:

  • Removed getStars() and the module cache; github.ts now only exports REPO + formatStars.
  • A single live fetch in the Landing layout updates both badges on load — the nav chip (star · N) and the hero button (N). Reuses formatStars; Astro tree-shakes the client bundle.
  • Neutral initial markup (nav star, hero empty hidden span), so there's nothing to go stale and no CI GitHub request / rate-limit dependency.

Result: every visitor sees the current count, no rebuilds, no cron, no CI API call.

Trade-off

The count now appears a fraction of a second after load (client fetch), and visitors with JS disabled / third-party requests blocked see the button without a number. Acceptable for a decorative badge, and in exchange the number can never be stale again.

Verification

  • bun run build — succeeds; built HTML has neutral badges, exactly one inlined GitHub fetch that updates both selectors.
  • bun run check (astro check) — 0 errors, 0 warnings.

Merging this touches site/**, which triggers the Pages deploy and ships the fix.

The count was baked in at build time (getStars() in src/lib/github.ts)
and only re-fetched when site/** changed and the Pages workflow ran, so
the hero button drifted behind the real count (showed 26 while the repo
was at 30).

Keep the build-time value as the no-JS fallback and add a small bundled
client script in Hero.astro that re-fetches stargazers_count from the
GitHub API on load and updates the badge, reusing formatStars. Always
render the .cnt span (hidden when empty) so the client can populate it
even if the build-time fetch was rate-limited to null.
Copilot AI review requested due to automatic review settings July 8, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds progressive enhancement to keep the landing page GitHub star count up to date without requiring a new site deploy, while preserving the build-time value as a no-JS fallback.

Changes:

  • Export REPO from the GitHub stars helper so it can be reused in client code.
  • Always render the .cnt span (hidden when empty) and add a small client-side fetch to refresh stargazers_count on page load.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
site/src/lib/github.ts Exports REPO for reuse outside build-time fetching.
site/src/components/Hero.astro Ensures the star count span is always present and refreshes the count via a client-side GitHub API fetch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread site/src/components/Hero.astro Outdated
<a class="starbtn" href="https://github.com/onsails/right-agent">
<svg class="ico" viewBox="0 0 24 24" width="15" height="15" fill="currentColor" aria-hidden="true"><path d="M12 2l2.9 6.9 7.1.6-5.4 4.7 1.6 7L12 18.3 5.8 21.2l1.6-7L2 9.5l7.1-.6z"/></svg>
star on github{starLabel && <span class="cnt">{starLabel}</span>}
star on github<span class="cnt" hidden={!starLabel}>{starLabel}</span>
…t-side

The build-time getStars() call was now redundant: the client already
re-fetches the live count, so the CI build's GitHub API request only
produced a value that goes stale between deploys (the original bug) and
depends on the unauthenticated CI rate limit.

Remove getStars()/the module cache and the await in Hero.astro and
Landing.astro. Render neutral initial badges (nav 'star', hero empty
hidden span) and consolidate refresh into a single fetch in the Landing
layout that updates BOTH badges — the nav chip (.starchip) and the hero
button (.starbtn .cnt). The nav chip was previously left stale; it is now
covered too.
@onsails onsails changed the title fix(site): refresh GitHub star count live on the landing page fix(site): live GitHub star count on the landing page (client-side, no build-time fetch) Jul 8, 2026
@onsails onsails merged commit f527eef into master Jul 8, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants