Skip to content

Commit

Permalink
🐛 fix: 修正 SSR 样式抽取失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed May 29, 2023
1 parent 93f6c12 commit a1ba99a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/core/CacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ export class CacheManager {
private _cacheList: EmotionCache[] = [cache];

add(cache: EmotionCache) {
if (!this._cacheList.includes(cache)) this._cacheList.push(cache);
if (this.hasCache(cache)) return;

this._cacheList.push(cache);
}

private hasCache(cache: EmotionCache) {
return this._cacheList.some((c) => c.key === cache.key);
}

getCacheList() {
Expand Down
11 changes: 10 additions & 1 deletion src/factories/createStyleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@ export const createStyleProvider = (EmotionContext: Context<Emotion>): FC<StyleP
const emotion = useMemo(() => {
const defaultSpeedy = process.env.NODE_ENV === 'development';

return createEmotion({
const instance = createEmotion({
speedy: speedy ?? defaultSpeedy,
key: prefix,
container: container as Node,
nonce,
insertionPoint,
stylisPlugins,
});

const cacheManager = global?.__ANTD_STYLE_CACHE_MANAGER_FOR_SSR__;

if (cacheManager) {
// add 方法有幂等
cacheManager.add(instance.cache);
}

return instance;
}, [prefix, speedy, container, nonce, insertionPoint, stylisPlugins]);

useEffect(() => {
Expand Down

0 comments on commit a1ba99a

Please sign in to comment.