Skip to content

fix(website): query GitHub API first for stars widget to avoid stale counts#229

Merged
singaraiona merged 1 commit into
masterfrom
fix/gh-stars-widget-staleness
Jun 8, 2026
Merged

fix(website): query GitHub API first for stars widget to avoid stale counts#229
singaraiona merged 1 commit into
masterfrom
fix/gh-stars-widget-staleness

Conversation

@singaraiona

Copy link
Copy Markdown
Collaborator

Problem

The GitHub stars/forks widget on the docs and marketing sites was showing stale (old) counts.

The widget queried ungh.cc first — a CDN-cached GitHub proxy that lags the real count by ~a day — falling back to the authoritative GitHub API only if ungh failed. The 1-hour localStorage cache then pinned that stale value per visitor. The original rationale (avoiding GitHub's 60-req/hour limit) doesn't really apply to a client-side fetch: each visitor spends their own IP's budget on one cached request per hour.

When checked live, both sources happened to agree (134★/19⑂), which is why the staleness was intermittent — it only showed while the count was moving.

Fix

  • Query the authoritative GitHub API first; fall back to ungh.cc only when the direct API is unreachable (e.g. a 403 on a shared/busy IP).
  • Add response shape validation on the GitHub payload so a malformed response triggers the fallback instead of painting NaN.
  • Applied to both copies: docs/javascripts/main.js and website/script.js.

The 1-hour localStorage cache is unchanged — it's reasonable and now caches a fresh value.

Notes

  • Existing visitors with a stale localStorage entry self-heal within the hour (or immediately on hard-reload).
  • The README.md shields.io social badge is a separate, independently-cached path and was left untouched.

🤖 Generated with Claude Code

…counts

The stars/forks widget queried ungh.cc first — a CDN-cached proxy that
lags GitHub by ~a day — and only fell back to the authoritative GitHub
API. Combined with the 1-hour localStorage cache, this surfaced stale
counts whenever the star total was moving.

Flip the priority: query api.github.com first (per-visitor 60/hour
unauthenticated limit is ample for one cached request/hour), with
ungh.cc as the resilience fallback for busy/shared IPs. Add response
shape validation so a malformed GitHub payload falls through instead of
painting NaN. Applied to both the docs and marketing-site copies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@singaraiona singaraiona merged commit a7e8485 into master Jun 8, 2026
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.

1 participant