Open
Description
How to safely keep a reference to uncommitted objects and dispose of them on unmount?
For a MobX world, we are trying to prepare for the Concurrent mode. In short, there is a Reaction object being created to track for observables and it is stored within useRef
.
The major problem is, that we can't just useEffect
to create it in a safe way later. We need it to start tracking the observables on a first render otherwise we might miss some updates and cause inconsistent behavior.
We do have a semi-working solution, basically, a custom made garbage collector based on setTimeout
. However, it's unreliable as it can accidentally dispose of Reactions that are actually being used but weren't committed yet.
Would love to hear we are overlooking some obvious solution there.