Skip to content

Commit d486051

Browse files
authored
[Devtools] Look for a ReactMemoCacheSentinel on state (#28831)
The useMemoCache polyfill doesn't have access to the fiber, and it simply uses state, which does not work with the existing devtools badge for the compiler. With this PR, devtools will look on the very first hook's state for the memo cache sentinel and display the Forget badge if present. The polyfill will add this sentinel to it's state (the cache array).
1 parent 1683cb1 commit d486051

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/react-devtools-shared/src/backend/ReactSymbols.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ export const SUSPENSE_LIST_SYMBOL_STRING = 'Symbol(react.suspense_list)';
6767

6868
export const SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED_SYMBOL_STRING =
6969
'Symbol(react.server_context.defaultValue)';
70+
71+
export const REACT_MEMO_CACHE_SENTINEL: symbol = Symbol.for(
72+
'react.memo_cache_sentinel',
73+
);

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import {
8686
STRICT_MODE_SYMBOL_STRING,
8787
PROFILER_NUMBER,
8888
PROFILER_SYMBOL_STRING,
89+
REACT_MEMO_CACHE_SENTINEL,
8990
SCOPE_NUMBER,
9091
SCOPE_SYMBOL_STRING,
9192
FORWARD_REF_NUMBER,
@@ -474,8 +475,12 @@ export function getInternalReactConstants(version: string): {
474475
}
475476

476477
let resolvedContext: any = null;
477-
// $FlowFixMe[incompatible-type] fiber.updateQueue is mixed
478-
if (!shouldSkipForgetCheck && fiber.updateQueue?.memoCache != null) {
478+
if (
479+
!shouldSkipForgetCheck &&
480+
// $FlowFixMe[incompatible-type] fiber.updateQueue is mixed
481+
(fiber.updateQueue?.memoCache != null ||
482+
fiber.memoizedState?.memoizedState?.[REACT_MEMO_CACHE_SENTINEL])
483+
) {
479484
const displayNameWithoutForgetWrapper = getDisplayNameForFiber(
480485
fiber,
481486
true,

0 commit comments

Comments
 (0)