Missing useEffect Cleanup
useEffect with timers, listeners or subscriptions and no cleanup, in client components
warningReliability
missing-useeffect-cleanupWhy this matters
Without cleanup, subscriptions and timers keep running after the component unmounts. This causes memory leaks, stale state updates, and 'can't update unmounted component' errors.
Example
components/notifications.tsx"use client";
import { useEffect } from "react";
export function Notifications() {
useEffect(() => {
const interval = setInterval(() => {
fetchNotifications();
}, 5000);
// No cleanup: the interval outlives the component
}, []);
return null;
}components/notifications.tsx"use client";
import { useEffect } from "react";
export function Notifications() {
useEffect(() => {
const interval = setInterval(() => {
fetchNotifications();
}, 5000);
return () => clearInterval(interval);
}, []);
return null;
}How to fix
Return a cleanup function from every useEffect that creates subscriptions, timers, event listeners, or WebSocket connections.
Reference
- In the output
- Findings carry
"ruleId": "missing-useeffect-cleanup"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line missing-useeffect-cleanup- Silence a whole file
// prodlint-disable missing-useeffect-cleanupat the top of the file- How it works
- Matches text patterns. Source on GitHub