Skip to content
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

[Mistake]: The demo of useOptimistic may occur an incorrect rendering #7379

Open
felismargarita opened this issue Dec 20, 2024 · 1 comment

Comments

@felismargarita
Copy link

Summary

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)

Page

https://react.dev/reference/react/useOptimistic

Details

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.

@karthik-awebon
Copy link

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
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants