Bug: [React 19] [Regression] Unexpected TypeError when useEffect returns null — "destroy is not a function" in React 19.x (cleanup now stricter)
Summary
After upgrading to React 19.x, code that previously returned null from a useEffect callback now throws TypeError: destroy is not a function during cleanup. Previously returning null or other non-function values often worked. This appears to be stricter runtime enforcement of the rule that an effect may only return a cleanup function or nothing.
Reproduction (minimal)
import React, { useEffect } from "react";
export default function App() {
useEffect(() => {
// early exit path that used to return null
if (Date.now() < 0) {
return null;
}
// normal effect (no cleanup)
console.log("effect ran");
}, []);
return <div>Test</div>;
}