Skip to content

fix(core): prevent setState crashing when used directly #211

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

Closed
wants to merge 1 commit into from

Conversation

ViewableGravy
Copy link

Overview

This fix resolves a bug introduced in 06c8227 which converted setState from an arrow function to a standard function. The change meant that the this context was no longer bound to the store, and would cause the function to crash when called directly const setState = store.setState.

Since this change was necessary for function definition overloading in typescript, This PR bounds the function to the store in the constructor and adds test cases for this scenario

@KevinVandy KevinVandy requested review from crutchcorn and Copilot June 27, 2025 04:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where calling setState via a detached reference would crash due to an unbound this context. Key changes include binding setState to the store instance in the constructor and adding a new test to ensure setState works correctly when not directly called on the store.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/store/tests/store.test.ts Added a test case validating that setState works via a detached reference.
packages/store/src/store.ts Binds setState to the store instance in the constructor to fix the context issue.

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