StrictMode double-invokes effects in development, deliberately

18 mounts, unmounts and remounts every component once in development under StrictMode, so an effect without cleanup runs twice and shows it.

useEffect(() => {
  const socket = connect(roomId)

  return () => socket.close()    // without this, two sockets
}, [roomId])

// what it is simulating: a future where React can preserve
// and restore component state, which requires effects to be
// resilient to being run twice.

// production is unaffected. this is a development-only
// check, and disabling StrictMode to make it stop is the
// wrong response.

Every failure it produces is a real defect — a subscription without a cleanup, a fetch that races itself, an analytics event fired twice. The temptation to remove StrictMode is strong in the first week and the bugs it surfaces are the ones that appear in production as a slow leak, which is much harder to attribute.