useAtomSelector's failsafe queueMicrotask is a little too aggressive and can (very rarely) lead to race conditions with React's own queued microtasks. #106 and Zedux v1.3.x already fix this for React 19, but React 18 is still the current version and still needs a better (temporary) fix.
Use requestIdleCallback (falling back to setTimeout in node) instead of queueMicrotask. This means (in StrictMode in React 18) that some leaked selector nodes will be visible for a short time before Zedux circles back and cleans them up, but it's better than being too aggressive and cleaning up graph edges that shouldn't be.
Description
useAtomSelector
's failsafequeueMicrotask
is a little too aggressive and can (very rarely) lead to race conditions with React's own queued microtasks. #106 and Zedux v1.3.x already fix this for React 19, but React 18 is still the current version and still needs a better (temporary) fix.Use
requestIdleCallback
(falling back tosetTimeout
in node) instead ofqueueMicrotask
. This means (in StrictMode in React 18) that some leaked selector nodes will be visible for a short time before Zedux circles back and cleans them up, but it's better than being too aggressive and cleaning up graph edges that shouldn't be.