-
Notifications
You must be signed in to change notification settings - Fork 48k
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
[React 19] Bug: optimisticState is updated with both new state and optimisticValue in useOptimistic #31944
Comments
Does happen to me as well on the provided CodeSandbox. The change between the optimistic state back to the original state does indeed occur with 2 renders. I guess it should be just 1 render probably. |
Yes, This is happening for me as well ref - https://codesandbox.io/p/sandbox/react-dev-forked-gmlxnr?file=%2Fsrc%2FApp.js&workspaceId=ws_QiCvK4c476hege6EDsXfpC as mentioned above Another similar sandbox - https://codesandbox.io/p/sandbox/react-19-useoptimistic-3f7htj?file=%2Fsrc%2FApp.js%3A52%2C5&workspaceId=ws_PszjWaELh3PS49RV1rnLom |
Anyone find a workaround for this yet? I've been beating my head against this for hours. It looks like |
What I ended up doing on my end to get around this for now: Luckily, everything we're using this for is CRUD-related operations, and we're using |
Using the react Example given for useOptimistic hook in docs, an update in state passed to the hook should directly reset the optimisticState in one render.
Instead
resets optimisticState with new State in another render cycle.
React.19.issue.mov
React version: 19
Steps To Reproduce
Link to code example:
https://codesandbox.io/p/sandbox/react-dev-forked-gmlxnr?file=%2Fsrc%2FApp.js&workspaceId=ws_QiCvK4c476hege6EDsXfpC
The current behavior
When new state is passed to useOptimistic,
The expected behavior
When new state is passed to useOptimistic, it should directly reset the optimisticState without calling the updater Fn
The text was updated successfully, but these errors were encountered: