Skip to content

Commit 23a3ad7

Browse files
committed
Add gating for prod too
1 parent 838aa6b commit 23a3ad7

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,12 @@ export function renderWithHooks<Props, SecondArg>(
424424
}
425425
} else {
426426
ReactCurrentDispatcher.current =
427-
current === null || current.memoizedState === null
428-
? HooksDispatcherOnMount
429-
: HooksDispatcherOnUpdate;
427+
current !== null &&
428+
((enableThrowOnMountForHookMismatch &&
429+
(current.mode & ConcurrentMode) !== NoMode) ||
430+
current.memoizedState !== null)
431+
? HooksDispatcherOnUpdate
432+
: HooksDispatcherOnMount;
430433
}
431434

432435
let children = Component(props, secondArg);

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ export function renderWithHooks<Props, SecondArg>(
407407
// be null during updates and mounts.
408408
if (
409409
current !== null &&
410-
(enableThrowOnMountForHookMismatch || current.memoizedState !== null)
410+
((enableThrowOnMountForHookMismatch &&
411+
(current.mode & ConcurrentMode) !== NoMode) ||
412+
current.memoizedState !== null)
411413
) {
412414
ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
413415
} else if (current !== null) {
@@ -422,9 +424,12 @@ export function renderWithHooks<Props, SecondArg>(
422424
}
423425
} else {
424426
ReactCurrentDispatcher.current =
425-
current === null || current.memoizedState === null
426-
? HooksDispatcherOnMount
427-
: HooksDispatcherOnUpdate;
427+
current !== null &&
428+
((enableThrowOnMountForHookMismatch &&
429+
(current.mode & ConcurrentMode) !== NoMode) ||
430+
current.memoizedState !== null)
431+
? HooksDispatcherOnUpdate
432+
: HooksDispatcherOnMount;
428433
}
429434

430435
let children = Component(props, secondArg);
@@ -484,8 +489,9 @@ export function renderWithHooks<Props, SecondArg>(
484489
const didRenderTooFewHooks =
485490
(currentHook !== null && currentHook.next !== null) ||
486491
(enableThrowOnMountForHookMismatch &&
487-
current !== null &&
488-
current.memoizedState !== null &&
492+
current != null &&
493+
(current.mode & ConcurrentMode) !== NoMode &&
494+
current.memoizedState != null &&
489495
workInProgress.memoizedState == null);
490496

491497
renderLanes = NoLanes;

0 commit comments

Comments
 (0)