Zustand Pressistant Accorss Page #3220
Unanswered
darshanhegde27
asked this question in
Bug report
Replies: 1 comment
-
i am still new to bug report help is appriciated current implemetion |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bug Description
Bug Report: Zustand store not updating state with first API response when multiple calls are made
Description
When the same API (orders) is called from two different pages (OrdersPage and DashboardPage), Zustand store does not update the state immediately after the first response is received. Instead, it waits until the last call completes before updating the state, causing delayed UI updates.
Steps to Reproduce
Create a Zustand store with an async function fetchOrders that fetches orders from an API and updates state.
Call fetchOrders simultaneously from two components (OrdersPage and DashboardPage).
Observe that the state/UI is not updated when the first response comes back — it only updates after the last request resolves.
Expected Behavior
State should update as soon as the first API response is available.
Subsequent responses can override or be merged depending on implementation, but UI should not "wait" for all requests to complete.
Actual Behavior
State update happens only after the last API request finishes, causing a noticeable delay in the UI.
Environment
Zustand version: latest
React version: 18
Browser: Chrome Latest Version
Possible Cause / Notes
This may be related to async actions overriding state due to race conditions.
Zustand’s default behavior doesn’t queue or dedupe async calls, so earlier results may be overwritten by later requests even if they finish later.
Suggested Fix
Provide a way to configure whether the first completed response should update the store immediately.
Optionally support cancellation / deduplication strategies so that multiple components don’t step on each other’s updates.
Reproduction Link
https://stackblitz.com/
Beta Was this translation helpful? Give feedback.
All reactions