Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ssrInline duplicate style #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hixuanxuan
Copy link

问题

在SSR场景ssrInine={true}导致重复的组件样式会被多次抽取打进html,导致文档的体积增大,nextjs里面无法直接使用rendertostring/renderToNodeStream

解决

利用记录次数,在服务端对于在cache中相同key对应的样式,只插入文档一次,并且利用react生命周期传递cache对象,不能使用defaultCache(次数是node的全局累计)

使用

'use client';

import {StyleProvider, createCache, legacyLogicalPropertiesTransformer} from '@ant-design/cssinjs';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import {ConfigProvider, App} from 'antd';
import zhCN from 'antd/locale/zh_CN';
import {antdTheme} from '@/lib/antd/antdTheme';

dayjs.locale('zh-cn');

export default function AntdProvider({children}: {
    children: React.ReactNode;
}) {
    const render = <>{children}</>;
    const cache = createCache();

    return (
        <StyleProvider
            ssrInline={true}
            hashPriority="high"
            cache={cache}
            transformers={[legacyLogicalPropertiesTransformer]}
        >
            <ConfigProvider
                locale={zhCN}
                theme={antdTheme}
            >
                <App className="h-full">
                    {render}
                </App>
            </ConfigProvider>
        </StyleProvider>
    );
}

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.88%. Comparing base (907a22b) to head (594a29c).

❗ Current head 594a29c differs from pull request most recent head d2c6e42. Consider uploading reports for the commit d2c6e42 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #175      +/-   ##
==========================================
+ Coverage   94.80%   94.88%   +0.07%     
==========================================
  Files          29       29              
  Lines        2619     2620       +1     
  Branches      394      396       +2     
==========================================
+ Hits         2483     2486       +3     
+ Misses        136      134       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants