Summary
react-doctor@0.9.14 reports react-doctor/effect-needs-cleanup for a React 19 callback ref that returns its ResizeObserver cleanup.
Reproduction
import { useCallback } from 'react';
export const useContainerWidth = () => {
const containerRef = useCallback((node: HTMLDivElement | null) => {
if (node === null) {
return;
}
const observer = new ResizeObserver(() => {});
observer.observe(node);
return () => observer.disconnect();
}, []);
return containerRef;
};
Actual result
React Doctor reports effect-needs-cleanup at observer.observe(node).
Expected result
No diagnostic. React 19 supports callback refs that return a cleanup function. React calls that cleanup when the referenced element detaches.
The callback's null branch owns no observer. Returning void there is valid according to the React ref callback type, which permits void | (() => void).
Environment
react-doctor: 0.9.14
react: 19.3.0
- TypeScript
Summary
react-doctor@0.9.14reportsreact-doctor/effect-needs-cleanupfor a React 19 callback ref that returns itsResizeObservercleanup.Reproduction
Actual result
React Doctor reports
effect-needs-cleanupatobserver.observe(node).Expected result
No diagnostic. React 19 supports callback refs that return a cleanup function. React calls that cleanup when the referenced element detaches.
The callback's
nullbranch owns no observer. Returningvoidthere is valid according to the React ref callback type, which permitsvoid | (() => void).Environment
react-doctor:0.9.14react:19.3.0