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
{{ message }}
Repository navigation
[Mistake]: The demo of useOptimistic may occur an incorrect rendering #7379
useOptimistic demo merges state via [...state, { text: newMessage, sending:true }], which may render a same message twice in the page at the same time(although it will render correct page immediately after the incorrect one)
merge message logic in this demo has to handle the situation:
state(array of the messages) already includes the sending message when the setMessages is called to make the page re-rendering.
Hello @felismargarita the existing code effectively demonstrates the use of the UseOptimistic Hook with a simple example. Adding unnecessary complexity to handle duplicate messages detracts from the core purpose of the demo.
Additionally, your PR does not function as intended. The use of time as a unique identifier for messages is flawed, as identical messages can still appear multiple times if their timestamps differ, as evidenced in the screenshot.
image
Activity
karthik-awebon commentedon Dec 20, 2024
Hello @felismargarita the existing code effectively demonstrates the use of the UseOptimistic Hook with a simple example. Adding unnecessary complexity to handle duplicate messages detracts from the core purpose of the demo.
Additionally, your PR does not function as intended. The use of time as a unique identifier for messages is flawed, as identical messages can still appear multiple times if their timestamps differ, as evidenced in the screenshot.

image
rickhanlonii commentedon Jan 28, 2026
Should be fixed in #8264