Skip to content

🐞[Bug]: Infinite fetch re-trigger cycle and totalPRs stat corruption in CommunityStatsProvider #2521

Closed

Description

@bobby404-K

Describe the bug

In src/lib/statsProvider.tsx, two significant bugs exist in data-fetching and state management:

  1. Infinite Re-trigger Cycle in fetchAllStats:
    fetchAllStats is wrapped in useCallback with cache in its dependency array:

    const fetchAllStats = useCallback(
      async (signal: AbortSignal) => {
        ...
        setCache({
          data: { ... },
          timestamp: now,
        });
      },
      [backendApiUrl, cache],
    );
    
    useEffect(() => {
      const abortController = new AbortController();
      fetchAllStats(abortController.signal);
      return () => { abortController.abort(); };
    }, [fetchAllStats]);

    Whenever fetchAllStats runs, it updates the cache state via setCache(...). Because cache is listed as a dependency of fetchAllStats, the fetchAllStats function reference changes on every execution. This immediately re-triggers the mount useEffect, causing redundant execution cycles and re-renders.

  2. Data Corruption in Raw Stats:
    On line 478:

    rawStats: { totalPRs: statsData.totalContributors },

    totalPRs is incorrectly mapped to statsData.totalContributors instead of statsData.totalPRs, corrupting PR count metrics in the raw cache.

  3. Dead Code & Unused Variables:
    GITHUB_ORG, MAX_CONCURRENT_REQUESTS, MAX_PAGES_PER_REPO, and calculatePointsForPR are unused declarations that trigger linter warnings.

Expected behavior

  1. fetchAllStats should have stable dependencies so the mount useEffect does not trigger redundant fetch cycles when cache updates.
  2. rawStats.totalPRs should correctly map to statsData.totalPRs.
  3. Unused variables should be cleaned up.

Activity

  1. github-actions commented on Nov 14, 2026

    @github-actions

    Thanks for opening this issue! 🎉 We'll look into it as soon as possible, estimated time for response is 5–8 hrs.

    Don't raise PR unless assigned to you.

    In the meantime, please provide all necessary details and context to your issue — screenshots or videos of your changes help speed up the review and assignment. If you have questions, reach out to LinkedIn. Your contributions are highly appreciated!😊

    Note: I maintain the repo issue every day twice at 8:00 AM IST and 9:00 PM IST. If your issue goes stale for more than one day, you can tag and comment on this same issue by tagging @sanjay-kv.

    We are here to help you on this journey of open source. Consistent contributions are eligible for sponsorship 💰

    🎁 check our list of amazing people we sponsored so far: GitHub Sponsorship. ✨

    📚Resources which can help you know more about Github 👇🏻

    1. End to End GitHub Beginner Playlist: GitHub Playlist.

    2. Build your GitHub Profile: GitHub Profile Optimisation.

    3. GitHub Handbook for dummies: GitHub Blog for Beginners.

  2. github-actions commented on Nov 14, 2026

    @github-actions

    Thanks for opening this issue. To help maintainers review it faster, please add the missing details below:

    • Fill in the "Describe the bug" section.
    • Fill in the "Expected behavior" section.
  3. bobby404-K commented on Nov 14, 2026

    @bobby404-K
    MemberAuthor

    assign me @sanjay-kv

  4. github-actions commented on Nov 15, 2026

    @github-actions

    👤 Issue assigned to @bobby404-K.

  5. github-actions commented on Nov 15, 2026

    @github-actions

    ✅ This issue has been closed. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

level 110 pointsrecodethis is label for leaderboard

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions