@@ -79,6 +79,7 @@ import {
79
79
PROVIDER_SYMBOL_STRING ,
80
80
CONTEXT_NUMBER ,
81
81
CONTEXT_SYMBOL_STRING ,
82
+ CONSUMER_SYMBOL_STRING ,
82
83
STRICT_MODE_NUMBER ,
83
84
STRICT_MODE_SYMBOL_STRING ,
84
85
PROFILER_NUMBER ,
@@ -525,6 +526,15 @@ export function getInternalReactConstants(version: string): {
525
526
case CONTEXT_NUMBER :
526
527
case CONTEXT_SYMBOL_STRING :
527
528
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
+
528
538
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
529
539
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
530
540
// NOTE Keep in sync with inspectElementRaw()
@@ -533,6 +543,10 @@ export function getInternalReactConstants(version: string): {
533
543
// NOTE: TraceUpdatesBackendManager depends on the name ending in '.Consumer'
534
544
// If you change the name, figure out a more resilient way to detect it.
535
545
return `${ resolvedContext . displayName || 'Context' } .Consumer` ;
546
+ case CONSUMER_SYMBOL_STRING :
547
+ // 19+
548
+ resolvedContext = fiber . type . _context ;
549
+ return `${ resolvedContext . displayName || 'Context' } .Consumer` ;
536
550
case STRICT_MODE_NUMBER :
537
551
case STRICT_MODE_SYMBOL_STRING :
538
552
return null ;
@@ -3178,8 +3192,14 @@ export function attach(
3178
3192
}
3179
3193
}
3180
3194
} 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
+ )
3183
3203
) {
3184
3204
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
3185
3205
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
@@ -3209,6 +3229,35 @@ export function attach(
3209
3229
}
3210
3230
}
3211
3231
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
+
3212
3261
current = current . return ;
3213
3262
}
3214
3263
}
0 commit comments