-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: useStorage update onFocus #1316
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 028b5a8:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in NextJS store, working good 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today I learned about this visibilitychange
event!
What's the purpose of this pull request?
Update useStorage hook on focus.
How it works?
IndexedDB is consistent across multiple windows. Sadly, we don't have a way of hooking into indexedDB to know when it has changed or not with our current dependencies,
idb-keyval
.To make the app consistent across multiple tabs, I propose the
onFocus
trick. The idea is to update the stored value onuseStorage
hook each time the tab is focused. This way, we ensure when the user sees a tab, it's in a consistent state.How to test it?
Open two tabs and add items to cart. Make sure the two carts display the same products.
More info at: https://vtex.slack.com/archives/C01AKAJDUEQ/p1653391800179519
Starters Deploy Preview