Sphere
Log in Join
☆ 3

useEffect runs twice in dev — is my cleanup wrong or is it StrictMode?

React 18.3, my fetch effect fires twice in development and I see two requests in the network tab. The cleanup function aborts the first request, but the server still receives it. In production the build seems to fire once. Should I remove StrictMode or change the effect?

⚑ Report

3 replies

☆ 3
S Sofia T. ·2026-11-07#1

It is StrictMode doing a deliberate mount, unmount, remount cycle in development. Your cleanup is fine. The abort signal just cannot guarantee the server never saw the request.

⚑ Report
☆ 0
R Rafa ·2026-11-11#2

So this is not a bug in my effect. Is there any reason to keep StrictMode if it makes debugging noisy?

⚑ Report
☆ 0
G glitch7 ·2026-11-14#3

Keep it. It catches effects that forget to clean up timers and subscriptions, which is a much worse class of bug. If the duplicate request bothers you, guard with a request-id or just accept it in dev.

⚑ Report
Log in to reply.