diff --git a/.dumi/theme/layouts/GlobalLayout.tsx b/.dumi/theme/layouts/GlobalLayout.tsx index 521d5cce79..2b46f9f980 100644 --- a/.dumi/theme/layouts/GlobalLayout.tsx +++ b/.dumi/theme/layouts/GlobalLayout.tsx @@ -107,6 +107,24 @@ const GlobalLayout: React.FC = () => { [isMobile, direction, updateSiteConfig, theme], ); + const demoPage = pathname.startsWith('/~demos'); + + // ============================ Render ============================ + let content: React.ReactNode = outlet; + + // Demo page should not contain App component + if (!demoPage) { + content = ( + + {outlet} + updateSiteConfig({ theme: nextTheme })} + /> + + ); + } + return ( { }, }} > - - {outlet} - {!pathname.startsWith('/~demos') && ( - updateSiteConfig({ theme: nextTheme })} - /> - )} - + {content} diff --git a/components/message/__tests__/hooks.test.tsx b/components/message/__tests__/hooks.test.tsx index cbf15a940a..4d5cf68f78 100644 --- a/components/message/__tests__/hooks.test.tsx +++ b/components/message/__tests__/hooks.test.tsx @@ -1,6 +1,7 @@ /* eslint-disable jsx-a11y/control-has-associated-label */ import React from 'react'; import { act } from 'react-dom/test-utils'; +import { StyleProvider, createCache, extractStyle } from '@ant-design/cssinjs'; import message from '..'; import { fireEvent, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; @@ -255,4 +256,19 @@ describe('message.hooks', () => { errorSpy.mockRestore(); }); + + it('not export style in SSR', () => { + const cache = createCache(); + + const Demo = () => { + const [, holder] = message.useMessage(); + + return {holder}; + }; + + render(); + + const styleText = extractStyle(cache, true); + expect(styleText).not.toContain('.ant-message'); + }); }); diff --git a/components/message/style/index.tsx b/components/message/style/index.tsx index 80cee4cbc5..7947347291 100644 --- a/components/message/style/index.tsx +++ b/components/message/style/index.tsx @@ -201,4 +201,7 @@ export default genComponentStyleHook( token.paddingSM }px`, }), + { + clientOnly: true, + }, ); diff --git a/components/notification/__tests__/hooks.test.tsx b/components/notification/__tests__/hooks.test.tsx index 795a80f9b8..6677108409 100644 --- a/components/notification/__tests__/hooks.test.tsx +++ b/components/notification/__tests__/hooks.test.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { StyleProvider, createCache, extractStyle } from '@ant-design/cssinjs'; import notification from '..'; import { fireEvent, pureRender, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; @@ -154,4 +155,19 @@ describe('notification.hooks', () => { errorSpy.mockRestore(); }); }); + + it('not export style in SSR', () => { + const cache = createCache(); + + const Demo = () => { + const [, holder] = notification.useNotification(); + + return {holder}; + }; + + render(); + + const styleText = extractStyle(cache, true); + expect(styleText).not.toContain('.ant-notification'); + }); }); diff --git a/components/notification/style/index.tsx b/components/notification/style/index.tsx index c14d08a802..c4bfa12e55 100644 --- a/components/notification/style/index.tsx +++ b/components/notification/style/index.tsx @@ -300,4 +300,7 @@ export default genComponentStyleHook( zIndexPopup: token.zIndexPopupBase + 50, width: 384, }), + { + clientOnly: true, + }, ); diff --git a/components/theme/util/genComponentStyleHook.ts b/components/theme/util/genComponentStyleHook.ts index 405a2ed4b1..2240734ad3 100644 --- a/components/theme/util/genComponentStyleHook.ts +++ b/components/theme/util/genComponentStyleHook.ts @@ -58,6 +58,10 @@ export default function genComponentStyleHook, ComponentTokenKey][]; + /** + * Only use component style in client side. Ignore in SSR. + */ + clientOnly?: boolean; }, ) { return (prefixCls: string): UseComponentStyleResult => { @@ -71,6 +75,7 @@ export default function genComponentStyleHook csp?.nonce!, + clientOnly: options?.clientOnly, }; // Generate style for all a tags in antd component. diff --git a/package.json b/package.json index 98607ae433..8c72d2cb2c 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ ], "dependencies": { "@ant-design/colors": "^7.0.0", - "@ant-design/cssinjs": "^1.13.2", + "@ant-design/cssinjs": "^1.14.0", "@ant-design/icons": "^5.1.0", "@ant-design/react-slick": "~1.0.0", "@babel/runtime": "^7.18.3",