11import * as React from 'react' ;
22import { pathKey , type KeyType } from '../Cache' ;
33import StyleContext from '../StyleContext' ;
4- import useCompatibleInsertionEffect from './useCompatibleInsertionEffect' ;
54import useEffectCleanupRegister from './useEffectCleanupRegister' ;
65import useHMR from './useHMR' ;
6+ import { useInsertionEffect } from 'react' ;
77
88export type ExtractStyle < CacheValue > = (
99 cache : CacheValue ,
@@ -74,20 +74,13 @@ export default function useGlobalCache<CacheType>(
7474 const cacheContent = cacheEntity ! [ 1 ] ;
7575
7676 // Remove if no need anymore
77- useCompatibleInsertionEffect (
77+ useInsertionEffect (
7878 ( ) => {
7979 onCacheEffect ?.( cacheContent ) ;
80- } ,
81- ( polyfill ) => {
8280 // It's bad to call build again in effect.
8381 // But we have to do this since StrictMode will call effect twice
8482 // which will clear cache on the first time.
85- buildCache ( ( [ times , cache ] ) => {
86- if ( polyfill && times === 0 ) {
87- onCacheEffect ?.( cacheContent ) ;
88- }
89- return [ times + 1 , cache ] ;
90- } ) ;
83+ buildCache ( ( [ times , cache ] ) => [ times + 1 , cache ] ) ;
9184
9285 return ( ) => {
9386 globalCache . opUpdate ( fullPathStr , ( prevCache ) => {
@@ -100,7 +93,7 @@ export default function useGlobalCache<CacheType>(
10093 // With polyfill, registered callback will always be called synchronously
10194 // But without polyfill, it will be called in effect clean up,
10295 // And by that time this cache is cleaned up.
103- if ( polyfill || ! globalCache . opGet ( fullPathStr ) ) {
96+ if ( ! globalCache . opGet ( fullPathStr ) ) {
10497 onCacheRemove ?.( cache , false ) ;
10598 }
10699 } ) ;
0 commit comments