Skip to content

Commit da25659

Browse files
committed
Fix DevTools
1 parent ffc0d77 commit da25659

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const PROFILER_SYMBOL_STRING = 'Symbol(react.profiler)';
5151
export const PROVIDER_NUMBER = 0xeacd;
5252
export const PROVIDER_SYMBOL_STRING = 'Symbol(react.provider)';
5353

54+
export const CONSUMER_SYMBOL_STRING = 'Symbol(react.consumer)';
55+
5456
export const SCOPE_NUMBER = 0xead7;
5557
export const SCOPE_SYMBOL_STRING = 'Symbol(react.scope)';
5658

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

+51-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979
PROVIDER_SYMBOL_STRING,
8080
CONTEXT_NUMBER,
8181
CONTEXT_SYMBOL_STRING,
82+
CONSUMER_SYMBOL_STRING,
8283
STRICT_MODE_NUMBER,
8384
STRICT_MODE_SYMBOL_STRING,
8485
PROFILER_NUMBER,
@@ -525,6 +526,15 @@ export function getInternalReactConstants(version: string): {
525526
case CONTEXT_NUMBER:
526527
case CONTEXT_SYMBOL_STRING:
527528
case SERVER_CONTEXT_SYMBOL_STRING:
529+
if (
530+
fiber.type._context === undefined &&
531+
fiber.type.Provider === fiber.type
532+
) {
533+
// In 19+, Context.Provider === Context, so this is a provider.
534+
resolvedContext = fiber.type;
535+
return `${resolvedContext.displayName || 'Context'}.Provider`;
536+
}
537+
528538
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
529539
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
530540
// NOTE Keep in sync with inspectElementRaw()
@@ -533,6 +543,10 @@ export function getInternalReactConstants(version: string): {
533543
// NOTE: TraceUpdatesBackendManager depends on the name ending in '.Consumer'
534544
// If you change the name, figure out a more resilient way to detect it.
535545
return `${resolvedContext.displayName || 'Context'}.Consumer`;
546+
case CONSUMER_SYMBOL_STRING:
547+
// 19+
548+
resolvedContext = fiber.type._context;
549+
return `${resolvedContext.displayName || 'Context'}.Consumer`;
536550
case STRICT_MODE_NUMBER:
537551
case STRICT_MODE_SYMBOL_STRING:
538552
return null;
@@ -3179,8 +3193,14 @@ export function attach(
31793193
}
31803194
}
31813195
} else if (
3182-
typeSymbol === CONTEXT_NUMBER ||
3183-
typeSymbol === CONTEXT_SYMBOL_STRING
3196+
// Detect pre-19 Context Consumers
3197+
(typeSymbol === CONTEXT_NUMBER || typeSymbol === CONTEXT_SYMBOL_STRING) &&
3198+
!(
3199+
// In 19+, CONTEXT_SYMBOL_STRING means a Provider instead.
3200+
// It will be handled in a different branch below.
3201+
// Eventually, this entire branch can be removed.
3202+
(type._context === undefined && type.Provider === type)
3203+
)
31843204
) {
31853205
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
31863206
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
@@ -3210,6 +3230,35 @@ export function attach(
32103230
}
32113231
}
32123232

3233+
current = current.return;
3234+
}
3235+
} else if (
3236+
// Detect 19+ Context Consumers
3237+
typeSymbol === CONSUMER_SYMBOL_STRING
3238+
) {
3239+
// This branch is 19+ only, where Context.Provider === Context.
3240+
// NOTE Keep in sync with getDisplayNameForFiber()
3241+
const consumerResolvedContext = type._context;
3242+
3243+
// Global context value.
3244+
context = consumerResolvedContext._currentValue || null;
3245+
3246+
// Look for overridden value.
3247+
let current = ((fiber: any): Fiber).return;
3248+
while (current !== null) {
3249+
const currentType = current.type;
3250+
const currentTypeSymbol = getTypeSymbol(currentType);
3251+
if (
3252+
// In 19+, these are Context Providers
3253+
currentTypeSymbol === CONTEXT_SYMBOL_STRING
3254+
) {
3255+
const providerResolvedContext = currentType;
3256+
if (providerResolvedContext === consumerResolvedContext) {
3257+
context = current.memoizedProps.value;
3258+
break;
3259+
}
3260+
}
3261+
32133262
current = current.return;
32143263
}
32153264
}

0 commit comments

Comments
 (0)