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

Avoid capturing onValue closure in useSubscription forever #31

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jul 17, 2024

An issue similar to #purescript-elmish/83

The useSubscription hook was directly subscribing the onValue callback to the subscription in init, thus capturing that particular instance of onValue forever, ignoring the fact that onValue may change from call to call.

To fix, made it work similar to useEffect - sending an actual message from the subscription and calling onValue from update.

Added a test to check that it happens correctly. While I was at it, added a similar test for useEffect.

Copy link
Collaborator

@mcordova47 mcordova47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for adding the tests!

@fsoikin fsoikin merged commit 0bdb439 into main Jul 17, 2024
3 checks passed
@fsoikin fsoikin deleted the fix-closure-bug branch July 17, 2024 15:09
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.

2 participants