@@ -32,12 +32,17 @@ import {
3232 enableDoubleInvokingEffects ,
3333} from 'shared/ReactFeatureFlags' ;
3434
35+ < << << << packages / react-reconciler / src / ReactFiberHooks . old . js
3536import {
3637 NoMode ,
3738 BlockingMode ,
3839 DebugTracingMode ,
3940 StrictMode ,
4041} from './ReactTypeOfMode' ;
42+ = === ===
43+ import { HostRoot } from './ReactWorkTags' ;
44+ import { NoMode , BlockingMode , DebugTracingMode } from './ReactTypeOfMode' ;
45+ > >>> >>> packages / react - reconciler / src / ReactFiberHooks . new . js
4146import {
4247 NoLane ,
4348 NoLanes ,
@@ -102,6 +107,7 @@ import {getIsRendering} from './ReactCurrentFiber';
102107import { logStateUpdateScheduled } from './DebugTracing' ;
103108import { markStateUpdateScheduled } from './SchedulingProfiler' ;
104109import { CacheContext } from './ReactFiberCacheComponent' ;
110+ import { createUpdate , enqueueUpdate } from './ReactUpdateQueue.new' ;
105111
106112const { ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals ;
107113
@@ -1812,12 +1818,31 @@ function refreshCache<T>(
18121818 try {
18131819 const eventTime = requestEventTime ( ) ;
18141820 const lane = requestUpdateLane ( provider ) ;
1821+ // TODO: Does Cache work in legacy mode? Should decide and write a test.
18151822 const root = scheduleUpdateOnFiber ( provider , lane , eventTime ) ;
1823+
1824+ let seededCache = null ;
18161825 if ( seedKey !== null && seedKey !== undefined && root !== null ) {
18171826 // TODO: Warn if wrong type
1818- const seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
1827+ seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
18191828 transferCacheToSpawnedLane ( root , seededCache , lane ) ;
18201829 }
1830+
1831+ if ( provider . tag === HostRoot ) {
1832+ const refreshUpdate = createUpdate ( eventTime , lane ) ;
1833+ refreshUpdate . payload = {
1834+ cacheInstance : {
1835+ provider : provider ,
1836+ cache :
1837+ // For the root cache, we won't bother to lazily initialize the
1838+ // map. Seed an empty one. This saves use the trouble of having
1839+ // to use an updater function. Maybe we should use this approach
1840+ // for non-root refreshes, too.
1841+ seededCache !== null ? seededCache : new Map ( ) ,
1842+ } ,
1843+ } ;
1844+ enqueueUpdate ( provider , refreshUpdate ) ;
1845+ }
18211846 } finally {
18221847 ReactCurrentBatchConfig . transition = prevTransition ;
18231848 }
@@ -1940,9 +1965,7 @@ function getCacheForType<T>(resourceType: () => T): T {
19401965 const cacheInstance : CacheInstance | null = readContext ( CacheContext ) ;
19411966 invariant (
19421967 cacheInstance !== null ,
1943- 'Tried to fetch data, but no cache was found. To fix, wrap your ' +
1944- "component in a <Cache /> boundary. It doesn't need to be a direct " +
1945- 'parent; it can be anywhere in the ancestor path' ,
1968+ 'Internal React error: Should always have a cache.' ,
19461969 ) ;
19471970 let cache = cacheInstance . cache ;
19481971 if ( cache === null ) {
0 commit comments