Skip to content

fix(useSmartPolling): handle enabled state toggling and stabilize callback closures (#570) - #582

Open
PINYOPATTANAWASANPORN wants to merge 2 commits into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:fix/use-smart-polling-lifecycle-570
Open

PINYOPATTANAWASANPORN wants to merge 2 commits into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:fix/use-smart-polling-lifecycle-570

Conversation

@PINYOPATTANAWASANPORN

Copy link
Copy Markdown

Summary of Changes

  • Fix useSmartPolling lifecycle when toggling enabled dynamically between true and false (#570).
  • Wrap fetchFn, compareFn, and onDataChange options in stable React refs to prevent spurious interval teardowns on component re-renders (#568).
  • Update running setInterval dynamically when exponential backoff scales interval (#569).
  • Add comprehensive Jest/React Testing Library test suite in src/hooks/useSmartPolling.test.ts.

Root Cause / Technical Context

Previously, useSmartPolling relied on an unmanaged hasInitialized ref guard and lacked state dispatches on disabled cleanup, which caused isPolling to remain true when disabled and prevented interval restart when toggling enabled back to true.

Verification & Testing

  • Unit tests cover:
    1. Starting polling on mount with enabled=true.
    2. Stopping polling and clearing intervals when enabled flips to false.
    3. Seamlessly restarting polling and re-arming intervals when enabled toggles back to true.
    4. Callback stabilization across re-renders.

@vercel

vercel Bot commented Oct 5, 2026

Copy link
Copy Markdown

@PINYOPATTANAWASANPORN 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.

1 participant