Skip to content

Commit

Permalink
[Devtools] Look for a ReactMemoCacheSentinel on state
Browse files Browse the repository at this point in the history
The polyfill doesn't have access to the fiber, and it simply uses state,
which makes it not work with the devtools.

With this PR, devtools will look for this special sentinel on very first
hook's state for this sentinel and display the Forget badge if present.

The poylfill will add this sentinel to it's state (the cache array).
  • Loading branch information
gsathya committed Apr 12, 2024
1 parent d012a32 commit 602b567
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {
STRICT_MODE_SYMBOL_STRING,
PROFILER_NUMBER,
PROFILER_SYMBOL_STRING,
REACT_MEMO_CACHE_SENTINEL,
SCOPE_NUMBER,
SCOPE_SYMBOL_STRING,
FORWARD_REF_NUMBER,
Expand Down Expand Up @@ -475,7 +476,11 @@ export function getInternalReactConstants(version: string): {

let resolvedContext: any = null;
// $FlowFixMe[incompatible-type] fiber.updateQueue is mixed
if (!shouldSkipForgetCheck && fiber.updateQueue?.memoCache != null) {
if (
!shouldSkipForgetCheck &&
(fiber.updateQueue?.memoCache != null ||
fiber.memoizedState?.memoizedState?.[REACT_MEMO_CACHE_SENTINEL])
) {
const displayNameWithoutForgetWrapper = getDisplayNameForFiber(
fiber,
true,
Expand Down

0 comments on commit 602b567

Please sign in to comment.