You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
It calls the updaterFn first, updates the optimisticState using new state and optimisticValue during one render cycle
resets optimisticState with new State in another render cycle.
As a result, both the new state and optimisticValue is rendered. Tried this in 20x slowdown
React.19.issue.mov
React version: 19
Steps To Reproduce
Throttle CPU to 20x slowdown
Type some input in text box and press submit
See that the optimistic state is displayed and then it is pushed down for an instant along with the new state
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
After receiving the actual results from the server and updating the messages in App component, the updateFn of useOptimistic runs again with the final updated state and optimisticValue ( which is now already part of the final state ), and returns the optimisticState with duplicate values ( one already part of the final state and one with sending:true ) for one render cycle,
but somehow ( Magically ) it renders with the correct state in the next render cycle ( Not sure how it identifies the duplicate value )
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: