Skip to content

Fix useSyncLocalStorage initial value loss #217

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmns
Copy link
Contributor

@tmns tmns commented Jul 11, 2025

Currently useSyncLocalStorage does not actually set the initial value in local storage, even though the comment here implies it does.

Relatedly, since the item never actually exists in storage, if the user updates some other item, and the effect here runs, the hook will start returning null for the value instead of the initial value. This can also of course happen if the user clears their storage / deletes said item, and subsequently updates another item.

I think expected behavior would be a) for the initial value to actually get saved in storage, and b) for the hook to revert back to returning the initial value when the item's been deleted. Open to other approaches though!

Realized this while working on some orderbook changes. When using this hook to manage the display preference (i.e. vertical / horizontal), the app will break if the user hasn't explicitly updated this preference and performs some action to trigger a storage update (e.g. change order type).

@tmns tmns self-assigned this Jul 11, 2025
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