Skip to content

Commit f43fe5a

Browse files
waleedlatif1claude
andcommitted
fix(github-stars): centralize fallback via initialData, remove stale constants
Move the placeholder star count into useGitHubStars as initialData with initialDataUpdatedAt: 0 so `data` is always a narrowed string while still refetching on mount. Fixes two Bugbot issues: stale '25.8k' in chat.tsx (vs '27.8k' in navbar) and empty-string return in fetchGitHubStars that bypassed `??` fallbacks in consumers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2d2555f commit f43fe5a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

apps/sim/app/(landing)/components/navbar/components/github-stars.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import { GithubOutlineIcon } from '@/components/icons'
44
import { useGitHubStars } from '@/hooks/queries/github-stars'
55

6-
const INITIAL_STARS = '27.8k'
7-
86
/**
97
* Client component that displays GitHub stars count.
108
*
@@ -13,18 +11,17 @@ const INITIAL_STARS = '27.8k'
1311
*/
1412
export function GitHubStars() {
1513
const { data: stars } = useGitHubStars()
16-
const displayStars = stars ?? INITIAL_STARS
1714

1815
return (
1916
<a
2017
href='https://github.com/simstudioai/sim'
2118
target='_blank'
2219
rel='noopener noreferrer'
2320
className='flex h-[30px] items-center gap-2 self-center rounded-[5px] px-3 transition-colors duration-200 group-hover:bg-[var(--landing-bg-elevated)]'
24-
aria-label={`GitHub repository — ${displayStars} stars`}
21+
aria-label={`GitHub repository — ${stars} stars`}
2522
>
2623
<GithubOutlineIcon className='h-[14px] w-[14px]' />
27-
<span aria-live='polite'>{displayStars}</span>
24+
<span aria-live='polite'>{stars}</span>
2825
</a>
2926
)
3027
}

apps/sim/app/chat/[identifier]/chat.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const DEFAULT_VOICE_SETTINGS = {
4747
voiceId: 'EXAVITQu4vr4xnSDxMaL', // Default ElevenLabs voice (Bella)
4848
}
4949

50-
const INITIAL_STARS = '25.8k'
51-
5250
/**
5351
* Converts a File object to a base64 data URL
5452
*/
@@ -423,7 +421,7 @@ export default function ChatClient({ identifier }: { identifier: string }) {
423421
return (
424422
<div className='dark fixed inset-0 z-[100] flex flex-col bg-[var(--landing-bg)] text-[var(--landing-text)]'>
425423
{/* Header component */}
426-
<ChatHeader chatConfig={chatConfig} starCount={starCount ?? INITIAL_STARS} />
424+
<ChatHeader chatConfig={chatConfig} starCount={starCount} />
427425

428426
{/* Message Container component */}
429427
<ChatMessageContainer

apps/sim/hooks/queries/github-stars.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export const githubStarsKeys = {
88
count: () => [...githubStarsKeys.all, 'count'] as const,
99
}
1010

11+
/**
12+
* Fallback star count shown before the first fetch resolves. Centralized here
13+
* so every consumer of `useGitHubStars` renders the same placeholder.
14+
*/
15+
export const GITHUB_STARS_FALLBACK = '27.8k'
16+
1117
async function fetchGitHubStars(signal?: AbortSignal): Promise<string> {
1218
const response = await fetch('/api/stars', {
1319
signal,
@@ -17,18 +23,24 @@ async function fetchGitHubStars(signal?: AbortSignal): Promise<string> {
1723
throw new Error('Failed to fetch GitHub stars')
1824
}
1925
const data = await response.json()
20-
return (data?.stars as string) ?? ''
26+
const value = data?.stars
27+
return typeof value === 'string' && value.length > 0 ? value : GITHUB_STARS_FALLBACK
2128
}
2229

2330
/**
2431
* Loads the formatted GitHub star count for the Sim repository.
2532
* The `/api/stars` endpoint caches upstream for 1 hour, so a 1-hour
2633
* staleTime keeps the client cache aligned with the server cache.
34+
* `initialData` + `initialDataUpdatedAt: 0` gives `data` a narrowed
35+
* `string` type from the first render while still triggering a refetch
36+
* on mount, so consumers never need a fallback or undefined check.
2737
*/
2838
export function useGitHubStars() {
2939
return useQuery({
3040
queryKey: githubStarsKeys.count(),
3141
queryFn: ({ signal }) => fetchGitHubStars(signal),
3242
staleTime: 60 * 60 * 1000,
43+
initialData: GITHUB_STARS_FALLBACK,
44+
initialDataUpdatedAt: 0,
3345
})
3446
}

0 commit comments

Comments
 (0)