Skip to content

Commit

Permalink
feat(sdk): Improve useStorage and Optimistic revalidate effect (#1186)
Browse files Browse the repository at this point in the history
* Timeout zero useStorage effect

* Timeout optimistic cart revalidate

* Remove timeout from setState
  • Loading branch information
igorbrasileiro authored Mar 25, 2022
1 parent b1c9d51 commit 08c616b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/sdk/src/cart/Optimistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export const OptimisticProvider = <T extends Item = Item>({
}

// Enqueue validation
queue = queue.then(revalidate)
setTimeout(() => {
queue = queue.then(revalidate)
}, 0)

return () => {
cancel = true
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/storage/useStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useStorage = <T>(key: string, initialValue: T | (() => T)) => {
}
}

effect()
setTimeout(effect, 0)

return () => {
cancel = true
Expand Down

0 comments on commit 08c616b

Please sign in to comment.