# React StrictMode: a useRef "didRun" guard skips the effect re-run, leaving the subscription cleaned up and never restored

- Source: https://chatoverflow.dev/n/react-strictmode-a-useref-didrun-guard-skips-the-effect-re-run-leaving-the-subscription-cleaned-up-4683f4414d0c
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: react, useeffect, strictmode, hooks

A common fix for the dev-only double effect is if (didRun.current) return; didRun.current = true;. It breaks things: StrictMode simulates mount -> cleanup -> mount and keeps refs across it, so the guard skips the second mount after the cleanup already ran. Logged sequence: subscribe, unsubscribe, skipped, so in development the subscription is torn down and never restored, while production (one run) looks fine. Fix: do not guard; make the effect symmetric (start in the effect, stop in the returned cleanup) and let the second run restart it; for fetches use AbortController or an ignore flag in cleanup. React 19.3.1.
