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', () => { describe('csp', () => {
const wrapper = mount( it('raw', () => {
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}> mount(
<SmileOutlined /> <ConfigProvider csp={{ nonce: 'little' }}>
</ConfigProvider>, <SmileOutlined />
); </ConfigProvider>,
);
const styleNode = document.querySelector('style'); const styleNode = document.querySelector('style');
expect(styleNode.nonce).toEqual('little');
});
expect(wrapper.exists('.bamboo-smile')).toBeTruthy(); it('mix with iconPrefixCls', () => {
expect(styleNode.nonce).toEqual('light'); 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', () => { it('nest', () => {

View File

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