@@ -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 ;
@@ -3178,8 +3192,14 @@ export function attach(
31783192 }
31793193 }
31803194 } else if (
3181- typeSymbol === CONTEXT_NUMBER ||
3182- typeSymbol === CONTEXT_SYMBOL_STRING
3195+ // Detect pre-19 Context Consumers
3196+ ( typeSymbol === CONTEXT_NUMBER || typeSymbol === CONTEXT_SYMBOL_STRING ) &&
3197+ ! (
3198+ // In 19+, CONTEXT_SYMBOL_STRING means a Provider instead.
3199+ // It will be handled in a different branch below.
3200+ // Eventually, this entire branch can be removed.
3201+ ( type . _context === undefined && type . Provider === type )
3202+ )
31833203 ) {
31843204 // 16.3-16.5 read from "type" because the Consumer is the actual context object.
31853205 // 16.6+ should read from "type._context" because Consumer can be different (in DEV).
@@ -3209,6 +3229,35 @@ export function attach(
32093229 }
32103230 }
32113231
3232+ current = current . return ;
3233+ }
3234+ } else if (
3235+ // Detect 19+ Context Consumers
3236+ typeSymbol === CONSUMER_SYMBOL_STRING
3237+ ) {
3238+ // This branch is 19+ only, where Context.Provider === Context.
3239+ // NOTE Keep in sync with getDisplayNameForFiber()
3240+ const consumerResolvedContext = type . _context ;
3241+
3242+ // Global context value.
3243+ context = consumerResolvedContext . _currentValue || null ;
3244+
3245+ // Look for overridden value.
3246+ let current = ( ( fiber : any ) : Fiber ) . return ;
3247+ while ( current !== null ) {
3248+ const currentType = current . type ;
3249+ const currentTypeSymbol = getTypeSymbol ( currentType ) ;
3250+ if (
3251+ // In 19+, these are Context Providers
3252+ currentTypeSymbol === CONTEXT_SYMBOL_STRING
3253+ ) {
3254+ const providerResolvedContext = currentType ;
3255+ if ( providerResolvedContext === consumerResolvedContext ) {
3256+ context = current . memoizedProps . value ;
3257+ break ;
3258+ }
3259+ }
3260+
32123261 current = current . return ;
32133262 }
32143263 }
0 commit comments