useSmartPolling stops polling after the first re-render because useBountyStatus passes inline fetchFn/compareFn/onDataChange
I maintainer di solito rispondono entro 1 giorno
@Biglamar ci sta già lavorando.
Dal 27/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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).
- Lingua principale
- TypeScript
- Stelle
- 1
- Fork
- 94
- Merge medio
- 1h 2m
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MergeFi/frontend
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
accessibility bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MergeFi/frontend#835 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MergeFi/frontend
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
zapcooking/frontend#946 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
WiliamRosa/cosmos-semantic-platform#40 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
liberation-data/drivine#733 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
makecindy/cindy#10062 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno