Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): make useAtomSelector wait for idle time to do failsafe cleanup #113

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

bowheart
Copy link
Collaborator

@bowheart bowheart commented Aug 10, 2024

Description

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.

@bowheart bowheart changed the title fix(react): make useAtomSelector wait for idle time to do failsafe … fix(react): make useAtomSelector wait for idle time to do failsafe cleanup Aug 12, 2024
@bowheart bowheart merged commit f88996e into master Sep 7, 2024
2 checks passed
@bowheart bowheart deleted the josh/increase-selector-timeout branch September 7, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant