Skip to content

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

Closed

Description

@felismargarita

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.

Activity

  1. karthik-awebon commented on Dec 20, 2024

    @karthik-awebon
    Contributor

    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

  2. rickhanlonii commented on Jan 28, 2026

    @rickhanlonii
    Member

    Should be fixed in #8264

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions