@@ -111,6 +111,10 @@ type ReactTypeOfSideEffectType = {|
111111 Placement : number ,
112112| } ;
113113
114+ type VersionFlags = { |
115+ enableLegacyContext : boolean ,
116+ | } ;
117+
114118// Some environments (e.g. React Native / Hermes) don't support the performace API yet.
115119const getCurrentTime =
116120 typeof performance === 'object' && typeof performance . now === 'function'
@@ -125,6 +129,7 @@ export function getInternalReactConstants(
125129 ReactPriorityLevels : ReactPriorityLevelsType ,
126130 ReactTypeOfSideEffect : ReactTypeOfSideEffectType ,
127131 ReactTypeOfWork : WorkTagMap ,
132+ versionFlags : VersionFlags ,
128133| } {
129134 const ReactTypeOfSideEffect : ReactTypeOfSideEffectType = {
130135 NoEffect : 0b00 ,
@@ -239,6 +244,14 @@ export function getInternalReactConstants(
239244 // End of copied code.
240245 // **********************************************************
241246
247+ let versionFlags : VersionFlags = {
248+ enableLegacyContext : true ,
249+ } ;
250+
251+ if ( gte ( version , '17.0.0' ) ) {
252+ versionFlags [ 'enableLegacyContext' ] = false ;
253+ }
254+
242255 function getTypeSymbol ( type : any ) : Symbol | number {
243256 const symbolOrNumber =
244257 typeof type === 'object' && type !== null ? type . $$typeof : type ;
@@ -368,6 +381,7 @@ export function getInternalReactConstants(
368381 ReactPriorityLevels,
369382 ReactTypeOfWork,
370383 ReactTypeOfSideEffect,
384+ versionFlags,
371385 } ;
372386}
373387
@@ -383,6 +397,7 @@ export function attach(
383397 ReactPriorityLevels,
384398 ReactTypeOfWork,
385399 ReactTypeOfSideEffect,
400+ versionFlags,
386401 } = getInternalReactConstants ( renderer . version ) ;
387402 const { NoEffect, PerformedWork, Placement} = ReactTypeOfSideEffect ;
388403 const {
@@ -2187,20 +2202,22 @@ export function attach(
21872202 context = stateNode . context ;
21882203 }
21892204 } 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;
22022220 }
2203- current = current.return;
22042221 }
22052222 }
22062223 } else if (
@@ -2282,6 +2299,7 @@ export function attach(
22822299 hooks = inspectHooksOfFiber (
22832300 fiber ,
22842301 ( renderer . currentDispatcherRef : any ) ,
2302+ versionFlags . enableLegacyContext ,
22852303 ) ;
22862304 } finally {
22872305 // Restore original console functionality.
0 commit comments