Skip to content

Commit

Permalink
suppress error for untyped updateQueue on "Fix useMemoCache with setS…
Browse files Browse the repository at this point in the history
…tate 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
1 parent b8da0e6 commit 03000dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ function renderWithHooksAgain<Props, SecondArg>(
workInProgressHook = null;

if (workInProgress.updateQueue != null) {
resetFunctionComponentUpdateQueue(workInProgress.updateQueue);
resetFunctionComponentUpdateQueue((workInProgress.updateQueue: any));
}

if (__DEV__) {
Expand Down

0 comments on commit 03000dd

Please sign in to comment.