fix: csp not work on icon (#34356)

This commit is contained in:
二货机器人 2022-03-08 14:01:53 +08:00 committed by GitHub
parent 6ef85f654d
commit 8fe8df777e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View File

@ -16,17 +16,30 @@ describe('ConfigProvider.Icon', () => {
});
});
it('basic', () => {
const wrapper = mount(
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
<SmileOutlined />
</ConfigProvider>,
);
describe('csp', () => {
it('raw', () => {
mount(
<ConfigProvider csp={{ nonce: 'little' }}>
<SmileOutlined />
</ConfigProvider>,
);
const styleNode = document.querySelector('style');
const styleNode = document.querySelector('style');
expect(styleNode.nonce).toEqual('little');
});
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
expect(styleNode.nonce).toEqual('light');
it('mix with iconPrefixCls', () => {
const wrapper = mount(
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
<SmileOutlined />
</ConfigProvider>,
);
const styleNode = document.querySelector('style');
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
expect(styleNode.nonce).toEqual('light');
});
});
it('nest', () => {

View File

@ -211,7 +211,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
const memoIconContextValue = React.useMemo(
() => ({ prefixCls: iconPrefixCls, csp }),
[iconPrefixCls],
[iconPrefixCls, csp],
);
let childNode = children;
@ -238,7 +238,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
);
}
if (iconPrefixCls) {
if (iconPrefixCls || csp) {
childNode = (
<IconContext.Provider value={memoIconContextValue}>{childNode}</IconContext.Provider>
);