@@ -31,6 +31,7 @@ import {
3131 enableUseRefAccessWarning ,
3232} from 'shared/ReactFeatureFlags' ;
3333
34+ import { HostRoot } from './ReactWorkTags' ;
3435import { NoMode , BlockingMode , DebugTracingMode } from './ReactTypeOfMode' ;
3536import {
3637 NoLane ,
@@ -94,6 +95,7 @@ import {getIsRendering} from './ReactCurrentFiber';
9495import { logStateUpdateScheduled } from './DebugTracing' ;
9596import { markStateUpdateScheduled } from './SchedulingProfiler' ;
9697import { CacheContext } from './ReactFiberCacheComponent' ;
98+ import { createUpdate , enqueueUpdate } from './ReactUpdateQueue.new' ;
9799
98100const { ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals ;
99101
@@ -1741,12 +1743,31 @@ function refreshCache<T>(
17411743 try {
17421744 const eventTime = requestEventTime ( ) ;
17431745 const lane = requestUpdateLane ( provider ) ;
1746+ // TODO: Does Cache work in legacy mode? Should decide and write a test.
17441747 const root = scheduleUpdateOnFiber ( provider , lane , eventTime ) ;
1748+
1749+ let seededCache = null ;
17451750 if ( seedKey !== null && seedKey !== undefined && root !== null ) {
17461751 // TODO: Warn if wrong type
1747- const seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
1752+ seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
17481753 transferCacheToSpawnedLane ( root , seededCache , lane ) ;
17491754 }
1755+
1756+ if ( provider . tag === HostRoot ) {
1757+ const refreshUpdate = createUpdate ( eventTime , lane ) ;
1758+ refreshUpdate . payload = {
1759+ cacheInstance : {
1760+ provider : provider ,
1761+ cache :
1762+ // For the root cache, we won't bother to lazily initialize the
1763+ // map. Seed an empty one. This saves use the trouble of having
1764+ // to use an updater function. Maybe we should use this approach
1765+ // for non-root refreshes, too.
1766+ seededCache !== null ? seededCache : new Map ( ) ,
1767+ } ,
1768+ } ;
1769+ enqueueUpdate ( provider , refreshUpdate ) ;
1770+ }
17501771 } finally {
17511772 ReactCurrentBatchConfig . transition = prevTransition ;
17521773 }
@@ -1869,9 +1890,7 @@ function getCacheForType<T>(resourceType: () => T): T {
18691890 const cacheInstance : CacheInstance | null = readContext ( CacheContext ) ;
18701891 invariant (
18711892 cacheInstance !== null ,
1872- 'Tried to fetch data, but no cache was found. To fix, wrap your ' +
1873- "component in a <Cache /> boundary. It doesn't need to be a direct " +
1874- 'parent; it can be anywhere in the ancestor path' ,
1893+ 'Internal React error: Should always have a cache.' ,
18751894 ) ;
18761895 let cache = cacheInstance . cache ;
18771896 if ( cache === null ) {
0 commit comments