From 17f804ed8e36ce86e9188b463d0b95d8c8eb3b56 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 20 Jul 2023 15:25:34 +0800 Subject: [PATCH 1/2] :bug: fix: emotion instance should use same cache (#80) * feat: createGlobal * fix: mutiple emotion instance with same cache * Revert "feat: createGlobal" This reverts commit da4b2e0aa0db87be7728405d983c5af2df1cb446. * chore: code clean --- src/core/CacheManager.ts | 16 ++++++++++++---- src/factories/createStyleProvider/index.tsx | 2 +- src/functions/createInstance.ts | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/CacheManager.ts b/src/core/CacheManager.ts index e9408b6f..41683289 100644 --- a/src/core/CacheManager.ts +++ b/src/core/CacheManager.ts @@ -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) { @@ -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; } diff --git a/src/factories/createStyleProvider/index.tsx b/src/factories/createStyleProvider/index.tsx index 62d9d385..195f5834 100644 --- a/src/factories/createStyleProvider/index.tsx +++ b/src/factories/createStyleProvider/index.tsx @@ -98,7 +98,7 @@ export const createStyleProvider = (EmotionContext: Context): FC(options: CreateOptions) => { const StyleProvider = createStyleProvider(EmotionContext); // 将 cache 存到全局管理器中 - cacheManager.add(emotion.cache); + emotion.cache = cacheManager.add(emotion.cache); // ******* 下面这些都和主题相关,如果做了任何改动,都需要排查一遍 ************* // From a114763204f2fd5ab72b7ae8bbe5842dfb5d1f72 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 20 Jul 2023 07:29:04 +0000 Subject: [PATCH 2/2] :bookmark: chore(release): v3.4.2-beta.1 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [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)) --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 427b4823..ed26fd0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index bb75702b..57c8cb1d 100644 --- a/package.json +++ b/package.json @@ -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",