From 961ed5b49098f7fdd8d34b64b2c251e731441609 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Mon, 5 Feb 2024 18:45:37 +0000 Subject: [PATCH] Patch devtools before running useMemo function in strict mode This fixes a regression https://github.com/facebook/react/pull/25583 where we stopped patching before calling useMemo function. --- packages/react-reconciler/src/ReactFiberHooks.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 12c3987095284..a3158a87bb85a 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -2635,10 +2635,12 @@ function mountMemo( ): T { const hook = mountWorkInProgressHook(); const nextDeps = deps === undefined ? null : deps; + const nextValue = nextCreate(); if (shouldDoubleInvokeUserFnsInHooksDEV) { + setIsStrictModeForDevtools(true); nextCreate(); + setIsStrictModeForDevtools(false); } - const nextValue = nextCreate(); hook.memoizedState = [nextValue, nextDeps]; return nextValue; } @@ -2657,10 +2659,12 @@ function updateMemo( return prevState[0]; } } + const nextValue = nextCreate(); if (shouldDoubleInvokeUserFnsInHooksDEV) { + setIsStrictModeForDevtools(true); nextCreate(); + setIsStrictModeForDevtools(false); } - const nextValue = nextCreate(); hook.memoizedState = [nextValue, nextDeps]; return nextValue; }