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

perf: 优化 config provider context 频繁触发渲染问题 #8196

Merged
merged 1 commit into from
Mar 4, 2024
Merged
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
45 changes: 27 additions & 18 deletions packages/provider/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,36 @@ const ConfigProviderContainer: React.FC<{
dayjs.locale(locale?.locale || 'zh-cn');
}, [locale?.locale]);

const configProviderDom = useMemo(() => {
const themeConfig = {
const themeConfig = useMemo(() => {
return {
...restConfig.theme,
hashId: hashId,
hashed: hashed && isNeedOpenHash(),
};
}, [restConfig.theme, hashId, hashed, isNeedOpenHash()]);

const proConfigContextValue = useMemo(() => {
return {
...proProvideValue!,
valueTypeMap: valueTypeMap || proProvideValue?.valueTypeMap,
token,
theme: tokenContext.theme as unknown as Theme<any, any>,
hashed,
hashId,
};
}, [
proProvideValue,
valueTypeMap,
token,
tokenContext.theme,
hashed,
hashId,
]);

const configProviderDom = useMemo(() => {
return (
<AntdConfigProvider {...restConfig} theme={{ ...themeConfig }}>
<ProConfigContext.Provider
value={{
...proProvideValue!,
valueTypeMap: valueTypeMap || proProvideValue?.valueTypeMap,
token,
theme: tokenContext.theme as unknown as Theme<any, any>,
hashed,
hashId,
}}
>
<AntdConfigProvider {...restConfig} theme={themeConfig}>
<ProConfigContext.Provider value={proConfigContextValue}>
<>
{autoClearCache && <CacheClean />}
{children}
Expand All @@ -342,13 +353,11 @@ const ConfigProviderContainer: React.FC<{

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
restConfig,
themeConfig,
proConfigContextValue,
autoClearCache,
children,
getPrefixCls,
hashId,
locale,
proProvideValue,
token,
]);

if (!autoClearCache) return configProviderDom;
Expand Down
Loading