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 useHookstate store switchover #409

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

speigg
Copy link
Contributor

@speigg speigg commented May 16, 2024

This PR adds support for store switchovers to useHookstate() for global and nested state. Local state behavior remains unchanged. Additionally, setting state after unmount no longer throws an error, which is more in line w/ how React's built-in useState hook works.

TLDR; Eliminated HOOKSTATE-111 and HOOKSTATE-106 exceptions.

closes #364

@speigg speigg force-pushed the fix-InitStateStoreSwitchover branch from ac337e2 to 139b9e2 Compare May 16, 2024 05:08

rerender({ source: newStore });

expect(renderTimes).toBe(3);
Copy link
Owner

Choose a reason for hiding this comment

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

could you please extend the tests to make sure we can do state set action after the store is reinitialized? same for other tests you put.

@@ -1056,7 +1066,8 @@ class Store implements Subscribable {
set(path: Path, value: StateValueAtPath): SetActionDescriptor {
if (this.edition < 0) {
// TODO convert to console log
Copy link
Owner

Choose a reason for hiding this comment

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

maybe remove TODO comment? and update web docs for this error code?

@avkonst
Copy link
Owner

avkonst commented Jun 23, 2024

Hi @speigg ... could you please let me know if you are planning to address my comments?

@speigg
Copy link
Contributor Author

speigg commented Jul 3, 2024

Hi @avkonst I'd be happy to address your comments as soon as I have finished taking care of other things on my plate. Might take me another week to get to this.

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.

Prevent HOOKSTATE-111 exception being raised during Vite and NextJS HMR
2 participants