@@ -1712,67 +1712,62 @@ function rerenderOpaqueIdentifier(): OpaqueIDType | void {
17121712}
17131713
17141714function mountRefresh() {
1715- // TODO: CacheInstance should never be null. Update type.
1716- const cacheInstance : CacheInstance | null = readContext ( CacheContext ) ;
1715+ const cacheInstance : CacheInstance = readContext ( CacheContext ) ;
17171716 return mountCallback ( refreshCache . bind ( null , cacheInstance ) , [ cacheInstance ] ) ;
17181717}
17191718
17201719function updateRefresh() {
1721- const cacheInstance : CacheInstance | null = readContext ( CacheContext ) ;
1720+ const cacheInstance : CacheInstance = readContext ( CacheContext ) ;
17221721 return updateCallback ( refreshCache . bind ( null , cacheInstance ) , [
17231722 cacheInstance ,
17241723 ] ) ;
17251724}
17261725
17271726function refreshCache< T > (
1728- cacheInstance: CacheInstance | null ,
1727+ cacheInstance: CacheInstance,
17291728 seedKey: ?() => T ,
17301729 seedValue : T ,
17311730) {
1732- if ( cacheInstance !== null ) {
1733- const provider = cacheInstance . provider ;
1734-
1735- // Inlined startTransition
1736- // TODO: Maybe we shouldn't automatically give this transition priority. Are
1737- // there valid use cases for a high-pri refresh? Like if the content is
1738- // super stale and you want to immediately hide it.
1739- const prevTransition = ReactCurrentBatchConfig . transition ;
1740- ReactCurrentBatchConfig . transition = 1 ;
1741- // TODO: Do we really need the try/finally? I don't think any of these
1742- // functions would ever throw unless there's an internal error.
1743- try {
1744- const eventTime = requestEventTime ( ) ;
1745- const lane = requestUpdateLane ( provider ) ;
1746- // TODO: Does Cache work in legacy mode? Should decide and write a test.
1747- const root = scheduleUpdateOnFiber ( provider , lane , eventTime ) ;
1748-
1749- let seededCache = null ;
1750- if ( seedKey !== null && seedKey !== undefined && root !== null ) {
1751- // TODO: Warn if wrong type
1752- seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
1753- transferCacheToSpawnedLane ( root , seededCache , lane ) ;
1754- }
1731+ const provider = cacheInstance . provider ;
1732+
1733+ // Inlined startTransition
1734+ // TODO: Maybe we shouldn't automatically give this transition priority. Are
1735+ // there valid use cases for a high-pri refresh? Like if the content is
1736+ // super stale and you want to immediately hide it.
1737+ const prevTransition = ReactCurrentBatchConfig . transition ;
1738+ ReactCurrentBatchConfig . transition = 1 ;
1739+ // TODO: Do we really need the try/finally? I don't think any of these
1740+ // functions would ever throw unless there's an internal error.
1741+ try {
1742+ const eventTime = requestEventTime ( ) ;
1743+ const lane = requestUpdateLane ( provider ) ;
1744+ // TODO: Does Cache work in legacy mode? Should decide and write a test.
1745+ const root = scheduleUpdateOnFiber ( provider , lane , eventTime ) ;
1746+
1747+ let seededCache = null ;
1748+ if ( seedKey !== null && seedKey !== undefined && root !== null ) {
1749+ // TODO: Warn if wrong type
1750+ seededCache = new Map ( [ [ seedKey , seedValue ] ] ) ;
1751+ transferCacheToSpawnedLane ( root , seededCache , lane ) ;
1752+ }
17551753
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- }
1771- } finally {
1772- ReactCurrentBatchConfig . transition = prevTransition ;
1754+ if ( provider . tag === HostRoot ) {
1755+ const refreshUpdate = createUpdate ( eventTime , lane ) ;
1756+ refreshUpdate . payload = {
1757+ cacheInstance : {
1758+ provider : provider ,
1759+ cache :
1760+ // For the root cache, we won't bother to lazily initialize the
1761+ // map. Seed an empty one. This saves use the trouble of having
1762+ // to use an updater function. Maybe we should use this approach
1763+ // for non-root refreshes, too.
1764+ seededCache !== null ? seededCache : new Map ( ) ,
1765+ } ,
1766+ } ;
1767+ enqueueUpdate ( provider , refreshUpdate ) ;
17731768 }
1774- } else {
1775- // TODO: CacheInstance should never be null. Update type.
1769+ } finally {
1770+ ReactCurrentBatchConfig . transition = prevTransition ;
17761771 }
17771772}
17781773
@@ -1887,11 +1882,7 @@ function dispatchAction<S, A>(
18871882}
18881883
18891884function getCacheForType < T > (resourceType: () => T ) : T {
1890- const cacheInstance : CacheInstance | null = readContext ( CacheContext ) ;
1891- invariant (
1892- cacheInstance !== null ,
1893- 'Internal React error: Should always have a cache.' ,
1894- ) ;
1885+ const cacheInstance : CacheInstance = readContext ( CacheContext ) ;
18951886 let cache = cacheInstance . cache ;
18961887 if ( cache === null ) {
18971888 cache = cacheInstance . cache = new Map ( ) ;
0 commit comments