Category: Next.js, React and TypeScript

React StrictMode launches effect twice in development

Read this guide in Polish

When you open the form in a developer environment you see two identical logs and two queries with effect. StrictMode mode intentionally launches an additional setup cycle and cleanup effect during development to detect wrong side effects.

How to identify the source of the problem

Determine whether the problem occurs only in the development or also in the built production application. Check that useEfect has the correct cleanup function and that the code does not create a subscription without release.

Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.

Repair steps

Add cleanup canceling or closing the subscription, and save the storage operations with idempotence on the server side. If the effect initiates the resource, ensure its unambiguous opening and closing instead of artificial blocking of the second flag start.

How to Test Solution

In production, the operation is planned, and in development, the additional test StrictMode leaves no double subscription.

Security and restrictions

Do not disable StrictMode just to hide the leak or an unidentifiable record.