Skip to content

fix(react): guard against circular prevCache refs in useAtomSelector#161

Merged
bowheart merged 1 commit intov1.xfrom
josh/160
Feb 5, 2025
Merged

fix(react): guard against circular prevCache refs in useAtomSelector#161
bowheart merged 1 commit intov1.xfrom
josh/160

Conversation

@bowheart
Copy link
Collaborator

@bowheart bowheart commented Feb 5, 2025

Description

Certain React rendering sequences can apparently cause the singly-linked WeakRef list added in #154 to reference in circles. This causes the while loop cleaning up weak refs to run infinitely. This can only happen in useAtomSelector's prevCache linked list, not useAtomSelector's or useAtomInstance's prevEdge linked lists.

Mark each node as materialized when it's visited to kick out of the while loop when it hits a node it's already seen. Verify this fixes the problem for useAtomSelector's prevCache linked list. Do the same for the prevEdge linked lists in useAtomSelector and useAtomInstance just in case something we change later possibly introduces the same problem for those.

I will add repro tests in a separate PR

Issues

Resolves #160

@bowheart bowheart merged commit 6b57968 into v1.x Feb 5, 2025
2 checks passed
@bowheart bowheart deleted the josh/160 branch February 5, 2025 16:54
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