Skip to content

fix(www): guard github/discord counters against invalid API responses#902

Merged
Yeom-JinHo merged 2 commits intomagicuidesign:mainfrom
Yeom-JinHo:fix/invalid-api-res
Mar 2, 2026
Merged

fix(www): guard github/discord counters against invalid API responses#902
Yeom-JinHo merged 2 commits intomagicuidesign:mainfrom
Yeom-JinHo:fix/invalid-api-res

Conversation

@Yeom-JinHo
Copy link
Collaborator

Description

This PR updates the social counter components in www to prevent runtime failures when external API responses are invalid or unavailable.

It adds defensive parsing and fallback handling for both GitHub stars and Discord online member counts.

Changes

  • Added safe count format helper (formatCompactCount) in:
    • apps/www/components/github-link.tsx
    • apps/www/components/discord-link.tsx
  • Refactored GitHub stars fetch logic into getStarsCount() with guards:
    • Returns 0 when fetch fails
    • Returns 0 when response is not ok
    • Returns 0 when payload shape is invalid (stargazers_count missing/non-numeric)
  • Refactored Discord member fetch logic into getActiveMembersCount() with guards:
    • Returns 0 when fetch fails
    • Returns 0 when response is not ok
    • Returns 0 when payload shape is invalid (presence_count missing/non-numeric)
  • Updated rendering logic to use validated numeric values only, instead of directly reading raw JSON fields.

Motivation

  • External APIs can return unexpected payloads (rate limits, errors, malformed responses).
  • Direct toLocaleString() calls on undefined values can crash prerender/build.
  • This change ensures stable rendering and safe fallback behavior for social counters.

Breaking Changes

  • None.

@vercel
Copy link

vercel bot commented Mar 2, 2026

@Yeom-JinHo is attempting to deploy a commit to the product-studio Team on Vercel.

A member of the Team first needs to authorize it.

@Yeom-JinHo Yeom-JinHo merged commit 765c454 into magicuidesign:main Mar 2, 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.

1 participant