Skip to content

fix(hooks): handle enabled toggling explicitly in useSmartPolling (#570) - #585

Open
Proxima84-code wants to merge 1 commit into
MergeFi:mainfrom
Proxima84-code:fix/use-smart-polling-toggle-enabled
Open

Proxima84-code wants to merge 1 commit into
MergeFi:mainfrom
Proxima84-code:fix/use-smart-polling-toggle-enabled

Conversation

@Proxima84-code

Copy link
Copy Markdown

Summary

Fixes #570.

In useSmartPolling, toggling enabled from true to false cleared the interval timer but deliberately refrained from dispatching STOP_POLLING to avoid unmount state warnings. Consequently, isPolling remained true, misleading consumers like useBountyStatus into reporting active polling. Furthermore, toggling back from false to true was skipped because hasInitialized.current remained true, permanently pausing polling until a tab visibility change.

Changes

  • Unmount separation: Dedicated an unmount-only cleanup effect (useEffect(() => () => { isMountedRef.current = false; }, [])) following the useClaimRace lacks the isMountedRef unmount guard that its sibling hook useSmartPolling already has #361 pattern, ensuring unmount safeguards do not interfere with hook parameter transitions.
  • Explicit enabled handling:
    • Toggling enabled: false clears the active interval and dispatches STOP_POLLING.
    • Toggling enabled: true starts polling immediately, schedules the interval, and dispatches START_POLLING when active.
  • Callback stability: Stored caller callbacks (fetchFn, compareFn, onDataChange) in refs so polling cycles remain stable across component re-renders.
  • Unit tests (src/hooks/useSmartPolling.test.ts): Added comprehensive test coverage verifying:
    1. Polling on mount when enabled=true.
    2. Idle state when mounted with enabled=false.
    3. enabled: true -> false stopping the interval and setting isPolling: false.
    4. enabled: false -> true immediately restarting polling and rescheduling the timer.
    5. In-flight unmount safety without state warnings.

@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

@Proxima84-code is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

useSmartPolling: toggling enabled off leaves isPolling=true, and toggling it back on never restarts polling

1 participant