Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update on "Fix useMemoCache with setState in render"
Fixes the bug that alexmckenley and mofeiZ found where setState-in-render can reset useMemoCache and cause an infinite loop. The bug was that renderWithHooksAgain() was not resetting hook state when rerendering (so useMemo values were preserved) but was resetting the updateQueue. This meant that the entire memo cache was cleared on a setState-in-render.

The fix here is to call a new helper function to clear the update queue. It nulls out other properties, but for memoCache it just sets the index back to zero.

[ghstack-poisoned]
  • Loading branch information
josephsavona committed Sep 6, 2024
commit b8da0e6c791ca835b6ba4f24531ece54cb1e8571
4 changes: 0 additions & 4 deletions packages/react-reconciler/src/__tests__/useMemoCache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,6 @@ describe('useMemoCache()', () => {
await act(() => setInput('hi!'));

// Once the input has updated, we go back to rendering the transition.
// We did not have process the first chunk again. We reused the
// computation from the earlier attempt.
if (gate(flags => flags.enableNoCloningMemoCache)) {
// We did not have process the first chunk again. We reused the
// computation from the earlier attempt.
Expand Down Expand Up @@ -630,8 +628,6 @@ describe('useMemoCache()', () => {

// Finish loading the data.
await act(() => updatedChunkB.resolve('B2'));
// We did not have process the first chunk again. We reused the
// computation from the earlier attempt.
if (gate(flags => flags.enableNoCloningMemoCache)) {
// We did not have process the first chunk again. We reused the
// computation from the earlier attempt.
Expand Down