dillon1000/react
Commit
Browse files 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.
Changed paths2 files
First-parent comparisonpackages/react-reconciler/src/ReactFiberHooks.js ModifiedM packages/react-reconciler/src/__tests__/ReactAsyncActions-test.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…