useSmartPolling stops polling after the first re-render because useBountyStatus passes inline fetchFn/compareFn/onDataChange
Maintainers usually reply within 1 day
@Biglamar is already working on this.
Since Sep 27, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
src/hooks/useSmartPolling.ts's main polling effect is keyed on [enabled, fetchData], and fetchData is a useCallback over [fetchFn, compareFn, interval, backoffMultiplier, maxBackoff, unchangedThreshold, onDataChange]. The effect only ever creates the interval once, guarded by hasInitialized:
useEffect(() => {
isMountedRef.current = true;
if (!enabled) return;
if (!hasInitialized.current) {
hasInitialized.current = true;
dispatch({ type: 'START_POLLING' });
fetchData();
intervalRef.current = setInterval(fetchData, currentIntervalRef.current);
}
return () => {
isMountedRef.current = false;
if (intervalRef.current) { clearInterval(intervalRef.current); intervalRef.current = null; }
};
}, [enabled, fetchData]);
src/hooks/useBountyStatus.ts, the only consumer, passes fetchFn, compareFn and onDataChange as inline arrow functions, so they get a new identity on every render. ClaimButton.tsx's own comment already acknowledges that useBountyStatus "rebuilds its fetchFn / compareFn / onDataChange inline on every render".
What actually happens
- Mount: the effect runs, calls
fetchData(), and startssetInterval. - The first fetch resolves:
setDataandsetIsLoading(false)trigger a re-render, so there's a newfetchDataidentity. - The effect's cleanup runs:
clearInterval(...)andisMountedRef.current = false. - The effect body re-runs:
isMountedRef.current = true, buthasInitialized.currentis alreadytrue, so no new interval is created.
From then on, nothing polls until the tab is hidden and shown again, because the separate visibilitychange effect restarts the interval. Meanwhile:
isPollingstaystrue, sinceSTOP_POLLINGis deliberately not dispatched in the cleanup.BountyStatuskeeps showing the pulsing green "live" dot.ClaimButton's 2s status refresh used for claim-race detection (#46) never fires.
Suggested fix
- Keep
fetchFn,compareFnandonDataChangein refs, updated every render, sofetchDatais identity-stable. - And/or drop the
hasInitializedguard so the effect re-creates the interval whenever it re-runs. - Add a test: render a component using
useBountyStatus, advance timers past several intervals, and assertfetchBountywas called more than once.
Related: #46 (introduced smart polling), #359 (test coverage for these hooks), #361 (isMountedRef guard).
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 94
- Avg merge
- 1h 2m
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MergeFi/frontend
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug testing
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
accessibility bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MergeFi/frontend#835 · 1 comment ·
Maintainers usually reply within 1 day
All issues in MergeFi/frontend
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zapcooking/frontend#946 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
WiliamRosa/cosmos-semantic-platform#40 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
liberation-data/drivine#733 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
makecindy/cindy#10062 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day