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

isOptimistic turns false before data are returned from server. #226

Open
cajkavlada opened this issue Oct 30, 2024 · 0 comments
Open

isOptimistic turns false before data are returned from server. #226

cajkavlada opened this issue Oct 30, 2024 · 0 comments

Comments

@cajkavlada
Copy link

cajkavlada commented Oct 30, 2024

I have switch which toggle value using useServerAction.
Everything works great but when using optimistic update the data becomes undefined for moment when switching from optimistic value to server returned value. Resulting in bad flicker of the switch.

In my client component I have folowing console log:
console.log("data: ", data, "isOptimistic: ", isOptimistic, "status:", status);

This prints when I flip the switch:
data: true isOptimistic: false status: success
data: true isOptimistic: true status: pending

This prints after server action request returns:
data: undefined isOptimistic: false: status pending
data: true isOptimistic: false status: success

data: undefined, isOptimistic: false is the problem because switch doesnt know what value to show.
It is fixed immedialy with: data: true, but quick flicker is anoying.

I believe data should get the optimistic value until isOptimistic is false.

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

1 participant