diff --git a/src/hooks/useStyleRegister.tsx b/src/hooks/useStyleRegister.tsx index b859850..529d29d 100644 --- a/src/hooks/useStyleRegister.tsx +++ b/src/hooks/useStyleRegister.tsx @@ -333,7 +333,11 @@ export const parseStyle = ( if (!root) { styleStr = `{${styleStr}}`; } else if (layer) { - styleStr = `@layer ${layer.name} {${styleStr}}`; + + // fixme: https://github.com/thysultan/stylis/pull/339 + if (styleStr) { + styleStr = `@layer ${layer.name} {${styleStr}}`; + } if (layer.dependencies) { effectStyle[`@layer ${layer.name}`] = layer.dependencies diff --git a/tests/layer.spec.tsx b/tests/layer.spec.tsx index 9d6335e..2c1850a 100644 --- a/tests/layer.spec.tsx +++ b/tests/layer.spec.tsx @@ -66,4 +66,34 @@ describe('layer', () => { const styles = Array.from(document.head.querySelectorAll('style')); expect(styles[0].innerHTML.trim()).toEqual('@layer shared,button;'); }); + + // TODO: try fix, If stylis is fixed, this case should not be needed here. + // https://github.com/thysultan/stylis/pull/339 + // https://github.com/ant-design/ant-design/issues/51867 + it('empty braces (#51867)', () => { + const theme = createTheme(() => ({})); + const Demo = () => { + useStyleRegister( + { + theme, + token: { _tokenKey: 'test' }, + path: ['shared'], + layer: { + name: 'shared', + }, + }, + () => [], + ); + return null; + }; + + render( + + + , + ); + + const styles = Array.from(document.head.querySelectorAll('style')); + expect(styles[0].innerHTML.trim()).toEqual(''); + }); });