Skip to content

Commit 03000dd

Browse files
committed
suppress error for untyped updateQueue 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]
1 parent b8da0e6 commit 03000dd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ function renderWithHooksAgain<Props, SecondArg>(
835835
workInProgressHook = null;
836836

837837
if (workInProgress.updateQueue != null) {
838-
resetFunctionComponentUpdateQueue(workInProgress.updateQueue);
838+
resetFunctionComponentUpdateQueue((workInProgress.updateQueue: any));
839839
}
840840

841841
if (__DEV__) {

0 commit comments

Comments
 (0)