@@ -111,6 +111,10 @@ type ReactTypeOfSideEffectType = {|
111
111
Placement : number ,
112
112
| } ;
113
113
114
+ type VersionFlags = { |
115
+ enableLegacyContext : boolean ,
116
+ | } ;
117
+
114
118
// Some environments (e.g. React Native / Hermes) don't support the performace API yet.
115
119
const getCurrentTime =
116
120
typeof performance === 'object' && typeof performance . now === 'function'
@@ -125,6 +129,7 @@ export function getInternalReactConstants(
125
129
ReactPriorityLevels : ReactPriorityLevelsType ,
126
130
ReactTypeOfSideEffect : ReactTypeOfSideEffectType ,
127
131
ReactTypeOfWork : WorkTagMap ,
132
+ versionFlags : VersionFlags ,
128
133
| } {
129
134
const ReactTypeOfSideEffect : ReactTypeOfSideEffectType = {
130
135
NoEffect : 0b00 ,
@@ -239,6 +244,14 @@ export function getInternalReactConstants(
239
244
// End of copied code.
240
245
// **********************************************************
241
246
247
+ let versionFlags : VersionFlags = {
248
+ enableLegacyContext : true ;
249
+ } ;
250
+
251
+ if ( gte ( version , '17.0.0' ) ) {
252
+ versionFlags [ 'enableLegacyContext' ] = false ;
253
+ }
254
+
242
255
function getTypeSymbol ( type : any ) : Symbol | number {
243
256
const symbolOrNumber =
244
257
typeof type === 'object' && type !== null ? type . $$typeof : type ;
@@ -368,6 +381,7 @@ export function getInternalReactConstants(
368
381
ReactPriorityLevels,
369
382
ReactTypeOfWork,
370
383
ReactTypeOfSideEffect,
384
+ versionFlags,
371
385
} ;
372
386
}
373
387
@@ -383,6 +397,7 @@ export function attach(
383
397
ReactPriorityLevels,
384
398
ReactTypeOfWork,
385
399
ReactTypeOfSideEffect,
400
+ versionFlags,
386
401
} = getInternalReactConstants ( renderer . version ) ;
387
402
const { NoEffect, PerformedWork, Placement} = ReactTypeOfSideEffect ;
388
403
const {
@@ -2187,20 +2202,22 @@ export function attach(
2187
2202
context = stateNode . context ;
2188
2203
}
2189
2204
} else {
2190
- // Try to extract legacyContext from stateless components
2191
- // which do not have stateNode
2192
- let current = fiber . return ;
2193
- let childContextFound = false ;
2194
- while ( current !== null && childContextFound === false ) {
2195
- if (
2196
- current . stateNode &&
2197
- current . stateNode . __reactInternalMemoizedMergedChildContext
2198
- ) {
2199
- childContextFound = true ;
2200
- context =
2201
- current . stateNode . __reactInternalMemoizedMergedChildContext ;
2205
+ if ( versionFlags . enableLegacyContext ) {
2206
+ // Try to extract legacyContext from stateless components
2207
+ // which do not have stateNode
2208
+ let current = fiber . return ;
2209
+ let childContextFound = false ;
2210
+ while ( current !== null && childContextFound === false ) {
2211
+ if (
2212
+ current . stateNode &&
2213
+ current . stateNode . __reactInternalMemoizedMergedChildContext
2214
+ ) {
2215
+ childContextFound = true ;
2216
+ context =
2217
+ current . stateNode . __reactInternalMemoizedMergedChildContext ;
2218
+ }
2219
+ current = current.return;
2202
2220
}
2203
- current = current.return;
2204
2221
}
2205
2222
}
2206
2223
} else if (
@@ -2282,6 +2299,7 @@ export function attach(
2282
2299
hooks = inspectHooksOfFiber (
2283
2300
fiber ,
2284
2301
( renderer . currentDispatcherRef : any ) ,
2302
+ versionFlags . enableLegacyContext ,
2285
2303
) ;
2286
2304
} finally {
2287
2305
// Restore original console functionality.
0 commit comments