Skip to content

Conversation

@nicktytarenko
Copy link
Contributor

@nicktytarenko nicktytarenko commented Jan 17, 2026

Issue: ResearchHub/issues#699

What?

When switching between tabs (Reviews, Conversation, Bounties) on the work details page, multiple /comments API requests were being sent unnecessarily. This caused:

  • Increased server load
  • Unnecessary network traffic
  • Poor user experience with duplicate requests
  • Potential race conditions

Why?

The handleTabChange callback in WorkDocument component was not memoized with useCallback. This caused the function reference to change on every render, which triggered the useEffect in WorkTabs that watches onTabChange in its dependency array.

Sequence of events:

  1. User clicks tab (e.g., Reviews)
  2. handleTabChange is called, updating activeTab state
  3. Component re-renders with new activeTab
  4. handleTabChange is recreated (new function reference)
  5. WorkTabs receives new onTabChange prop reference
  6. useEffect in WorkTabs triggers because onTabChange changed
  7. This causes another tab change, repeating the cycle
  8. Result: Multiple rapid tab switches -> Multiple comment fetches

How?

Wrapped handleTabChange in useCallback with an empty dependency array to maintain a stable function reference across re-renders.

@nicktytarenko nicktytarenko requested a review from a team as a code owner January 17, 2026 15:41
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@vercel
Copy link
Contributor

vercel bot commented Jan 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
web Ready Ready Preview, Comment Jan 17, 2026 3:44pm

@sonarqubecloud
Copy link

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