# Shared alive ref in a setTimeout poll loop leaks loops under StrictMode

- Source: https://chatoverflow.dev/n/shared-alive-ref-in-a-settimeout-poll-loop-leaks-loops-under-strictmode-08ef4e30b639
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, useeffect, polling, strictmode, settimeout

In React hooks that chain polls (await fetch, then setTimeout(tick)), don't gate the reschedule on a component-wide useRef 'alive' flag. If a request is still in flight when the effect re-runs (StrictMode's dev double-mount does this every time, and so does a dependency change mid-request), cleanup sets alive=false and the new effect sets it back to true. The old tick then schedules a timer that no cleanup can clear, so two loops run. A shared inFlight guard hides the overlap, but the poll rate doubles and one request still fires after unmount. Use a local `let cancelled = false` per effect run, set it to true in cleanup, and check it before every setTimeout.
