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

the demo of useOptimistic has some bugs #6412

Closed
JackWuyulong opened this issue Nov 6, 2023 · 4 comments
Closed

the demo of useOptimistic has some bugs #6412

JackWuyulong opened this issue Nov 6, 2023 · 4 comments
Assignees

Comments

@JackWuyulong
Copy link

i found some bugs when i run the demo of useOptimistic. The result of list always show the final value instead of all my input value if i input quickly.
Kapture 2023-11-06 at 17 41 06

Then i awared of why the result like this. Because the function of sendMessages isn't right.
async function sendMessage(formData) { const sentMessage = await deliverMessage(formData.get("message")); **setMessages([...messages, { text: sentMessage }]);** }
it should be like below:
setMessages((messages) =>[...messages,{text:sentMessage}] )

i hope to get reply, thanks

@mattcarrollcode
Copy link
Contributor

Thanks for the bug report! I've reproduced the error, and looks like a race condition.

Link to page with the problematic code sample: https://react.dev/reference/react/useOptimistic#optimistically-updating-with-forms

Pointer to the code that has the bug: https://github.com/reactjs/react.dev/blob/main/src/content/reference/react/useOptimistic.md?plain=1#L119

@kmiddleton14
Copy link
Contributor

This should now be fixed. Thank you for reporting!

@thedv91
Copy link

thedv91 commented Mar 17, 2024

error

When I set a longer timeout. Is this an error?

@rickhanlonii
Copy link
Member

@thedv91 yes, we're tracking that here: facebook/react#28574 (comment)

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

No branches or pull requests

5 participants