@@ -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 ;
@@ -3179,8 +3193,14 @@ export function attach(
3179
3193
}
3180
3194
}
3181
3195
} 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
+ )
3184
3204
) {
3185
3205
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
3186
3206
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
@@ -3210,6 +3230,35 @@ export function attach(
3210
3230
}
3211
3231
}
3212
3232
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
+
3213
3262
current = current . return ;
3214
3263
}
3215
3264
}
0 commit comments