Description
Describe the bug
the useEffect
call in useFlag
registers listeners on the client but has no teardown defined. This means that over time, as components which check flag statuses are added and removed, the number of listeners will increase, gradually increasing memory use and reducing app performance (and causing react to complain about "setState called on unmounted component" whenever the flag changes after a component has unmounted).
proxy-client-react/src/useFlag.ts
Lines 10 to 24 in e5614d7
Steps to reproduce the bug
const Thing = () => {
const flag = useFlag('foo');
return null;
};
const App = () => {
// some rough example code which will display the component for 1 second, then remove it
const [show, setShow] = useState(true);
useEffect(() => { setTimeout(() => setShow(false), 1000); }, []);
return <FlagProvider config={{/*blah*/}}>{show && <Thing />}</FlagProvider>;
};
If the foo
flag changes after the component disappears, a warning about calling setState on an unmounted component will appear in the console (once the client refreshes).
Expected behavior
registered listeners should be removed in useEffect
's teardown
Logs, error output, etc.
No response
Screenshots
No response
Additional context
No response
Unleash version
No response
Subscription type
No response
Hosting type
No response
SDK information (language and version)
proxy-client-react