Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: emotion instance should use same cache (#80) #81

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.4.2-beta.1](https://github.com/ant-design/antd-style/compare/v3.4.1...v3.4.2-beta.1) (2023-07-20)

### 🐛 Bug Fixes

- Emotion instance should use same cache, closes [#80](https://github.com/ant-design/antd-style/issues/80) ([17f804e](https://github.com/ant-design/antd-style/commit/17f804e))

## [3.4.1](https://github.com/ant-design/antd-style/compare/v3.4.0...v3.4.1) (2023-07-02)

### 🐛 Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antd-style",
"version": "3.4.1",
"version": "3.4.2-beta.1",
"description": "a css-in-js solution for application combine with antd v5 token system and emotion",
"keywords": [
"antd",
Expand Down
16 changes: 12 additions & 4 deletions src/core/CacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { EmotionCache } from '@emotion/css/create-instance';
export class CacheManager {
private _cacheList: EmotionCache[] = [cache];

add(cache: EmotionCache) {
if (this.hasCache(cache)) return;

this._cacheList.push(cache);
add(cache: EmotionCache): EmotionCache {
const existCache = this.getCache(cache.key);
if (existCache) {
return existCache;
} else {
this._cacheList.push(cache);
return cache;
}
}

delete(cache: EmotionCache) {
Expand All @@ -18,6 +22,10 @@ export class CacheManager {
return this._cacheList.some((c) => c.key === cache.key);
}

getCache(key: string) {
return this._cacheList.find((c) => c.key === key);
}

getCacheList() {
return this._cacheList;
}
Expand Down
2 changes: 1 addition & 1 deletion src/factories/createStyleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const createStyleProvider = (EmotionContext: Context<Emotion>): FC<StyleP

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

return instance;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const createInstance = <T = any>(options: CreateOptions<T>) => {
const StyleProvider = createStyleProvider(EmotionContext);

// 将 cache 存到全局管理器中
cacheManager.add(emotion.cache);
emotion.cache = cacheManager.add(emotion.cache);

// ******* 下面这些都和主题相关,如果做了任何改动,都需要排查一遍 ************* //

Expand Down