File tree 3 files changed +19
-7
lines changed 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'
2
1
import { InvariantError } from '../../shared/lib/invariant-error'
2
+ import { cacheScopeAsyncStorage } from '../../client/components/cache-scope-storage.external'
3
3
4
4
export function createCacheScope ( ) {
5
5
const storage = createCacheMap ( )
6
6
return {
7
7
run : < T > ( callback : ( ) => T ) : T => {
8
- return CacheScopeStorage . run ( storage , ( ) => callback ( ) )
8
+ return cacheScopeAsyncStorage . run ( storage , ( ) => callback ( ) )
9
9
} ,
10
10
}
11
11
}
@@ -33,15 +33,12 @@ function createCacheMap(): CacheMap {
33
33
}
34
34
35
35
function isWithinCacheScope ( ) {
36
- return ! ! CacheScopeStorage . getStore ( )
36
+ return ! ! cacheScopeAsyncStorage . getStore ( )
37
37
}
38
38
39
- const CacheScopeStorage : AsyncLocalStorage < CacheMap > =
40
- new AsyncLocalStorage < CacheMap > ( )
41
-
42
39
/** forked from packages/react-server/src/flight/ReactFlightServerCache.js */
43
40
function resolveCache ( ) : CacheMap {
44
- const store = CacheScopeStorage . getStore ( )
41
+ const store = cacheScopeAsyncStorage . getStore ( )
45
42
if ( store ) {
46
43
return store
47
44
}
You can’t perform that action at this time.
0 commit comments