Fix: Optimistic update does not get reset (#27453)
I found a bug where if an optimistic update causes a component to rerender, and there are no other state updates during that render, React bails out without applying the update. Whenever a hook detects a change, we must mark the component as dirty to prevent a bailout. We check for changes by comparing the new state to `hook.memoizedState`. However, when implementing optimistic state rebasing, I incorrectly reset `hook.memoizedState` to the incoming base state, even though I only needed to reset `hook.baseState`. This was just a mistake on my part. This wasn't caught by the existing tests because usually when the optimistic state changes, there's also some other state that marks the component as dirty in the same render. I fixed the bug and added a regression test.
A
Andrew Clark committed
85c2b519b54269811002d26f4f711809ef68f123
Parent: db69f95
Committed by GitHub <noreply@github.com>
on 10/3/2023, 7:01:40 PM