Skip to content

Commit 9fa6156

Browse files
authored
Merge pull request #145 from ant-design/beta
🐛 fix: fix rerender with ThemeSwitcher
2 parents eb426b3 + 86f9d06 commit 9fa6156

File tree

7 files changed

+90
-82
lines changed

7 files changed

+90
-82
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [3.6.2-beta.1](https://github.com/ant-design/antd-style/compare/v3.6.1...v3.6.2-beta.1) (2024-03-24)
4+
5+
### 🐛 Bug Fixes
6+
7+
- Fix rerender with ThemeSwitcher ([8669b88](https://github.com/ant-design/antd-style/commit/8669b88))
8+
39
## [3.6.1](https://github.com/ant-design/antd-style/compare/v3.6.0...v3.6.1) (2023-12-08)
410

511
### 🐛 Bug Fixes

package.json

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "antd-style",
3-
"version": "3.6.1",
3+
"version": "3.6.2-beta.1",
44
"description": "css-in-js solution for application combine with antd v5 token system and emotion",
55
"keywords": [
66
"antd",
@@ -69,72 +69,72 @@
6969
]
7070
},
7171
"dependencies": {
72-
"@ant-design/cssinjs": "^1",
73-
"@babel/runtime": "^7",
74-
"@emotion/cache": "^11",
75-
"@emotion/css": "^11",
76-
"@emotion/react": "^11",
77-
"@emotion/serialize": "^1",
78-
"@emotion/server": "^11",
79-
"@emotion/utils": "^1",
80-
"use-merge-value": "^1"
72+
"@ant-design/cssinjs": "^1.18.5",
73+
"@babel/runtime": "^7.24.1",
74+
"@emotion/cache": "^11.11.0",
75+
"@emotion/css": "^11.11.2",
76+
"@emotion/react": "^11.11.4",
77+
"@emotion/serialize": "^1.1.3",
78+
"@emotion/server": "^11.11.0",
79+
"@emotion/utils": "^1.2.1",
80+
"use-merge-value": "^1.2.0"
8181
},
8282
"devDependencies": {
83-
"@ant-design/icons": "^5",
84-
"@commitlint/cli": "^17",
85-
"@emotion/jest": "^11",
86-
"@emotion/styled": "^11",
87-
"@floating-ui/react": "^0.24",
88-
"@lobehub/i18n-cli": "^1.14.3",
89-
"@react-three/fiber": "^8",
90-
"@testing-library/jest-dom": "^5",
91-
"@testing-library/react": "^13",
92-
"@types/fs-extra": "^11.0.1",
93-
"@types/jest": "^27",
94-
"@types/lodash": "^4",
95-
"@types/react": "^18",
96-
"@types/react-dom": "^18",
97-
"@types/testing-library__jest-dom": "^5",
98-
"@umijs/lint": "^4",
83+
"@ant-design/icons": "^5.3.5",
84+
"@commitlint/cli": "^17.8.1",
85+
"@emotion/jest": "^11.11.0",
86+
"@emotion/styled": "^11.11.0",
87+
"@floating-ui/react": "^0.24.8",
88+
"@lobehub/i18n-cli": "^1.15.4",
89+
"@react-three/fiber": "^8.15.19",
90+
"@testing-library/jest-dom": "^5.17.0",
91+
"@testing-library/react": "^13.4.0",
92+
"@types/fs-extra": "^11.0.4",
93+
"@types/jest": "^27.5.2",
94+
"@types/lodash": "^4.17.0",
95+
"@types/react": "^18.2.69",
96+
"@types/react-dom": "^18.2.22",
97+
"@types/testing-library__jest-dom": "^5.14.9",
98+
"@umijs/lint": "^4.1.5",
9999
"@vitest/coverage-v8": "0.34.6",
100-
"antd": "^5",
101-
"babel-plugin-antd-style": "^1",
102-
"chalk": "^4",
103-
"classnames": "^2",
104-
"commitlint": "^17",
105-
"commitlint-config-gitmoji": "^2",
106-
"concurrently": "^7",
107-
"cross-env": "^7",
108-
"dumi": "^2",
100+
"antd": "^5.15.3",
101+
"babel-plugin-antd-style": "^1.0.4",
102+
"chalk": "^4.1.2",
103+
"classnames": "^2.5.1",
104+
"commitlint": "^17.8.1",
105+
"commitlint-config-gitmoji": "^2.3.1",
106+
"concurrently": "^7.6.0",
107+
"cross-env": "^7.0.3",
108+
"dumi": "^2.2.17",
109109
"dumi-theme-antd-style": "latest",
110-
"eslint": "^8",
111-
"father": "^4",
112-
"framer-motion": "^8",
113-
"framer-motion-3d": "^8",
114-
"fs-extra": "^11",
115-
"gh-pages": "^5",
116-
"history": "^5",
117-
"husky": "^8",
118-
"jsdom": "^22",
119-
"lint-staged": "^13",
120-
"lodash": "^4",
121-
"prettier": "^2",
122-
"prettier-plugin-organize-imports": "^3",
123-
"prettier-plugin-packagejson": "^2",
124-
"react": "^18",
125-
"react-dom": "^18",
126-
"react-layout-kit": "^1",
127-
"react-use-measure": "^2",
128-
"semantic-release": "^19",
129-
"semantic-release-config-gitmoji": "^1",
130-
"styled-components": "^6.0.0-rc.3",
131-
"stylelint": "^14",
132-
"three": "^0.148",
133-
"ts-node": "^10",
134-
"typescript": "^5",
135-
"vite": "^4.5.0",
110+
"eslint": "^8.57.0",
111+
"father": "^4.4.0",
112+
"framer-motion": "^8.5.5",
113+
"framer-motion-3d": "^8.5.5",
114+
"fs-extra": "^11.2.0",
115+
"gh-pages": "^5.0.0",
116+
"history": "^5.3.0",
117+
"husky": "^8.0.3",
118+
"jsdom": "^22.1.0",
119+
"lint-staged": "^13.3.0",
120+
"lodash": "^4.17.21",
121+
"prettier": "^2.8.8",
122+
"prettier-plugin-organize-imports": "^3.2.4",
123+
"prettier-plugin-packagejson": "^2.4.12",
124+
"react": "^18.2.0",
125+
"react-dom": "^18.2.0",
126+
"react-layout-kit": "^1.9.0",
127+
"react-use-measure": "^2.1.1",
128+
"semantic-release": "^19.0.5",
129+
"semantic-release-config-gitmoji": "^1.5.3",
130+
"styled-components": "^6.1.8",
131+
"stylelint": "^14.16.1",
132+
"three": "^0.148.0",
133+
"ts-node": "^10.9.2",
134+
"typescript": "^5.4.3",
135+
"vite": "^4.5.2",
136136
"vitest": "0.34.6",
137-
"zustand": "^4"
137+
"zustand": "^4.5.2"
138138
},
139139
"peerDependencies": {
140140
"antd": ">=5.8.1",

src/core/createCSS.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { serializeStyles } from '@emotion/serialize';
77
const createClassNameGenerator =
88
(cache: EmotionCache, options: ClassNameGeneratorOption): ClassNameGenerator =>
99
(...args) => {
10+
// @ts-ignore
1011
const serialized = serializeStyles(args, cache.registered, undefined);
1112

1213
insertStyles(cache, serialized, false, options);

src/core/createSerializeStyles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ export interface SerializeCSS {
1414
* 提供给 createStyles 方法,用于将用户写入的 css 字符串序列化成特定结构的样式对象
1515
* @param args
1616
*/
17-
export const serializeCSS: SerializeCSS = (...args) => serializeStyles(args);
17+
export const serializeCSS: SerializeCSS = (...args) =>
18+
// @ts-ignore
19+
serializeStyles(args);

src/factories/createThemeProvider/AntdProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ const AntdProvider: FC<AntdProviderProps> = memo(
6767
},
6868
);
6969

70+
AntdProvider.displayName = 'AntdProvider';
71+
7072
export default AntdProvider;

src/factories/createThemeProvider/ThemeSwitcher.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, memo, ReactNode, useEffect, useLayoutEffect, useState } from 'react';
1+
import { FC, memo, ReactNode, useLayoutEffect, useState } from 'react';
22
import useMergeValue from 'use-merge-value';
33

44
import { ThemeModeContext } from '@/context';
@@ -120,16 +120,6 @@ const ThemeSwitcher: FC<ThemeSwitcherProps> = memo(
120120
matchBrowserPrefers('dark')?.matches ? 'dark' : 'light',
121121
);
122122

123-
const [startObserver, setStartObserver] = useState(false);
124-
125-
// Wait until after client-side hydration to show
126-
useEffect(() => {
127-
// 兼容 React18 的 Suspense 问题
128-
safeStartTransition(() => {
129-
setStartObserver(true);
130-
});
131-
}, []);
132-
133123
return (
134124
<ThemeModeContext.Provider
135125
value={{
@@ -141,17 +131,22 @@ const ThemeSwitcher: FC<ThemeSwitcherProps> = memo(
141131
browserPrefers,
142132
}}
143133
>
144-
{startObserver && (
145-
<ThemeObserver
146-
themeMode={themeMode}
147-
setAppearance={setAppearance}
148-
setBrowserPrefers={setBrowserPrefers}
149-
/>
150-
)}
134+
{
135+
// Wait until after client-side hydration to show
136+
typeof window !== 'undefined' && (
137+
<ThemeObserver
138+
themeMode={themeMode}
139+
setAppearance={setAppearance}
140+
setBrowserPrefers={setBrowserPrefers}
141+
/>
142+
)
143+
}
151144
{children}
152145
</ThemeModeContext.Provider>
153146
);
154147
},
155148
);
156149

150+
ThemeSwitcher.displayName = 'ThemeSwitcher';
151+
157152
export default ThemeSwitcher;

src/functions/createInstance.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext } from 'react';
1+
import { createContext, FC } from 'react';
22

33
import { CacheManager, createCSS, createEmotion, serializeCSS } from '@/core';
44

@@ -109,6 +109,8 @@ export const createInstance = <T = any>(options: CreateOptions<T>) => {
109109
useTheme,
110110
});
111111

112+
(ThemeProvider as FC).displayName = 'AntdStyleThemeProvider';
113+
112114
// ******** 上面这些都和主题相关,如果做了任何改动,都需要排查一遍 ************ //
113115
const { cx } = createCSS(emotion.cache, { hashPriority: internalOptions.hashPriority });
114116
const { injectGlobal, keyframes } = emotion;

0 commit comments

Comments
 (0)