Skip to content

Commit

Permalink
Merge pull request #574 from oceanbase/zhuyue-dev
Browse files Browse the repository at this point in the history
fix(design): ConfigProvider should not inject StaticFunction many times by default
  • Loading branch information
dengfuping authored Apr 25, 2024
2 parents e433358 + efd6ec5 commit 16b0a5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { useContext } from 'react';
import { render } from '@testing-library/react';
import { ConfigProvider, useToken } from '@oceanbase/design';
import { injectedStaticFunction } from '../../static-function';

describe('ConfigProvider injectStaticFunction', () => {
it('injectStaticFunction', () => {
const Child = () => {
expect(injectedStaticFunction).toBe(true);
return <div />;
};
render(
<ConfigProvider>
<Child />
</ConfigProvider>
);
});
});
4 changes: 2 additions & 2 deletions packages/design/src/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { StyleProviderProps } from '@ant-design/cssinjs';
import StyleContext from '@ant-design/cssinjs/es/StyleContext';
import type { StyleContextProps } from '@ant-design/cssinjs/es/StyleContext';
import { merge } from 'lodash';
import StaticFunction from '../static-function';
import StaticFunction, { injectedStaticFunction } from '../static-function';
import themeConfig from '../theme';
import defaultTheme from '../theme/default';
import darkTheme from '../theme/dark';
Expand Down Expand Up @@ -97,7 +97,7 @@ const ConfigProvider: ConfigProviderType = ({
spin,
table,
tabs,
injectStaticFunction = true,
injectStaticFunction = !injectedStaticFunction,
styleProviderProps,
...restProps
}) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/design/src/static-function/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ let modal: Omit<ModalStaticFunctions, 'warn'> & {
useModal: typeof AntModal.useModal;
} = AntModal;

// injected static function or not
let injectedStaticFunction = false;

export default () => {
// 自动注入 useToken,避免每次使用都要声明一遍,比较繁琐
token = useToken().token;
Expand All @@ -54,7 +57,8 @@ export default () => {
...staticFunction.modal,
useModal: AntModal.useModal,
};
injectedStaticFunction = true;
return null;
};

export { token, message, notification, modal };
export { token, message, notification, modal, injectedStaticFunction };

0 comments on commit 16b0a5b

Please sign in to comment.