File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1+ import { createAsyncLocalStorage } from './async-local-storage'
2+ import type { CacheScopeStorageAsyncStorage } from './cache-scope-storage.external'
3+
4+ export const cacheScopeAsyncStorage : CacheScopeStorageAsyncStorage =
5+ createAsyncLocalStorage ( )
Original file line number Diff line number Diff line change 1+ import type { AsyncLocalStorage } from 'async_hooks'
2+
3+ // Share the instance module in the next-shared layer
4+ import { cacheScopeAsyncStorage } from './cache-scope-storage-instance' with { 'turbopack-transition' : 'next-shared' }
5+
6+ type CacheMap = Map < Function , unknown >
7+
8+ export type CacheScopeStorageAsyncStorage = AsyncLocalStorage < CacheMap >
9+
10+ export { cacheScopeAsyncStorage }
Original file line number Diff line number Diff line change 1- import { AsyncLocalStorage } from 'async_hooks'
21import { InvariantError } from '../../shared/lib/invariant-error'
2+ import { cacheScopeAsyncStorage } from '../../client/components/cache-scope-storage.external'
33
44export function createCacheScope ( ) {
55 const storage = createCacheMap ( )
66 return {
77 run : < T > ( callback : ( ) => T ) : T => {
8- return CacheScopeStorage . run ( storage , ( ) => callback ( ) )
8+ return cacheScopeAsyncStorage . run ( storage , ( ) => callback ( ) )
99 } ,
1010 }
1111}
@@ -33,15 +33,12 @@ function createCacheMap(): CacheMap {
3333}
3434
3535function isWithinCacheScope ( ) {
36- return ! ! CacheScopeStorage . getStore ( )
36+ return ! ! cacheScopeAsyncStorage . getStore ( )
3737}
3838
39- const CacheScopeStorage : AsyncLocalStorage < CacheMap > =
40- new AsyncLocalStorage < CacheMap > ( )
41-
4239/** forked from packages/react-server/src/flight/ReactFlightServerCache.js */
4340function resolveCache ( ) : CacheMap {
44- const store = CacheScopeStorage . getStore ( )
41+ const store = cacheScopeAsyncStorage . getStore ( )
4542 if ( store ) {
4643 return store
4744 }
You can’t perform that action at this time.
0 commit comments