Skip to content

2.0.0-rc.0 createOptimisticStore works inconsistently/unintuitively #3021

Description

@DominicDolan

Describe the bug

I'm not sure if this is a bug or if my understanding of createOptimistic/action is flawed but sometimes I have a hard time understanding how these work together. If it's not a bug then I find it fairly unintuitive.

I created a stackblitz example here. In it there are 2 versions of a todo example with a simulated backend. The first one uses createOptimisticStore as the way to store the todos, the second one just uses createStore instead.

In the optimistic example a lot of it works the way I would expect. You can add or remove todos and the updates show up straight away. In the store example there is a pause while it waits for the backend work to complete.

However, in the store example it behaves in an optimistic way for updating todos. Marking a todo as done or updating it's name shows up straight away, it doesn't wait. I don't really understand what I'm doing differently between adding/removing vs updating.

The second thing that I find more confusing is that in the optimistic example, clicking the save button on a todo after editing it causes it to wait, setIsEditing(false) doesn't resolve until the transition is finished. While in the store example this doesn't happen. Which seems reversed to me, why is the optimistic version waiting? Also, the isEditing is just an ordinary signal, why is its behaviour tied to whether I use a store or an optimistic store?

Your Example Website or App

https://stackblitz.com/edit/vitejs-vite-faxvqtln?file=src%2FTodo.tsx

Steps to Reproduce the Bug or Issue

  1. Go to https://stackblitz.com/edit/vitejs-vite-faxvqtln
  2. Add a todo
  3. Edit the todo's name
  4. Save the todo.

There is a wait time before isEditing() returns false again

  1. Click on "Store" at the top
  2. Add a todo
  3. Edit the todo's name
  4. Click save

There is no wait time for isEditing() to return false again

Expected behavior

.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions