How to run useEffect’s cleanup function when a suspended component unmounts?

When a suspended component unmounts, useEffect’s cleanup function doesn’t run. This leads to memory leaks, unused event handlers, etc. This makes useEffect unintuitive to use, since we’d typically assume the cleanup function always runs when the component unmounts.

Is there a good way to make the useEffect cleanup function run if the component was suspended before unmounting?