Skip to content
useOptimistic removed about 80 lines of state juggling from our comment box
link1.4K viewsAug 5, 2026

useOptimistic removed about 80 lines of state juggling from our comment box

Lena Fischer
Lena Fischer@lenafischer

August 5, 2026 · 1 min read

1.4K views3 comments

We had a pending-items array, a reconciliation effect, and a bug where a failed request left a ghost item. All of that is now the hook plus a server action.

Written by

Lena Fischer

Lena Fischer

Front-end engineer on a design systems team. I maintain the token pipeline and the component library four product teams build on. Strong opinions about focus rings, colour contrast, and the fact that most "theming" problems are really naming problems. CSS is a real language and I will keep saying so.

3 Comments

Sign in to join the discussion

Priya Raman
Priya Raman@priyaraman1mo ago

The ghost item left behind by a failed request is a bug I have now written in three different frameworks.

0
Sana Qureshi
Sana Qureshi@sanaqureshi1mo ago

Does it handle the case where the server returns a different shape than the one you optimistically rendered?

0
Lena Fischer
Lena Fischer@lenafischer1mo ago

It replaces the optimistic state with whatever the action returns, so the reconciliation is 'throw away my guess when the truth arrives'. The trap is doing work in the optimistic reducer that the server does differently — if your guess and the server disagree about ordering, users see a jump on every send.

0