Skip to content

Commit

Permalink
fix: hmr should rebuild cache (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Jul 26, 2023
1 parent c8a9393 commit d907912
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/hooks/useGlobalCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,25 @@ export default function useGlobalCache<CacheType>(

// Create cache
React.useMemo(
() => buildCache(),
() => {
buildCache();
},
/* eslint-disable react-hooks/exhaustive-deps */
[deps],
/* eslint-enable */
);

const cacheContent = globalCache.get(fullPath)![1];
let cacheEntity = globalCache.get(fullPath);

// HMR clean the cache but not trigger `useMemo` again
// Let's fallback of this
// ref https://github.com/ant-design/cssinjs/issues/127
if (process.env.NODE_ENV !== 'production' && !cacheEntity) {
buildCache();
cacheEntity = globalCache.get(fullPath);
}

const cacheContent = cacheEntity![1];

// Remove if no need anymore
useCompatibleInsertionEffect(
Expand Down

0 comments on commit d907912

Please sign in to comment.