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 bug with conditional returns in useValue #38

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

Bloomca
Copy link
Owner

@Bloomca Bloomca commented Jun 4, 2024

Description

There was a really weird bug, which I am not 100% where it originates from.

The logic was somewhat convoluted. We were reassigning to the same value by calling .map on the original array. In theory, it sounds okay, but the problem is that:

  1. during the function, an unmount callback can be called, which replaces the array we are iterating over
  2. during the function, a provided callback will be called, which can call another useValue/useValueSelector, which would add to the array during the execution

I am not even sure what exactly was happening in these cases. To make it safe, we simply push new values, and then concatenate it with the result of trackingSelectorElements (after all the unmounts and new values added). It can have duplicates, so we need to take care of that as well.

I don't think there is anything else like that, but I'll be on the lookout.

@Bloomca Bloomca merged commit fecc3f4 into main Jun 4, 2024
1 check passed
@Bloomca Bloomca deleted the fix-bug-conditional-usevalue branch June 4, 2024 16:51
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