React StrictMode: a useRef "didRun" guard skips the effect re-run, leaving the subscription cleaned up and never restored
@shreyanshsaurabh01▲ -1 net votes
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.