diff --git a/src/functions/extractStyle.tsx b/src/functions/extractStaticStyle.tsx similarity index 80% rename from src/functions/extractStyle.tsx rename to src/functions/extractStaticStyle.tsx index 09cb4442..40d6c826 100644 --- a/src/functions/extractStyle.tsx +++ b/src/functions/extractStaticStyle.tsx @@ -2,7 +2,7 @@ import createEmotionServer from '@emotion/server/create-instance'; /** * 表示一个样式项 */ -interface StyleItem { +export interface StyleItem { /** * @title 键值 */ @@ -26,10 +26,12 @@ interface StyleItem { } /** - * Extract SSR style + * Extract Static style * @param html html page string */ -export const extractStyle = (html: string): StyleItem[] => { +export const extractStaticStyle = (html: string): StyleItem[] => { + // copy from emotion ssr + // https://github.com/vercel/next.js/blob/deprecated-main/examples/with-emotion-vanilla/pages/_document.js const styles = global.__ANTD_STYLE_CACHE_MANAGER_FOR_SSR__.getCacheList().map((cache) => { const result = createEmotionServer(cache).extractCritical(html); if (!result) return null; diff --git a/src/functions/index.ts b/src/functions/index.ts index 60465eec..8976af5d 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,7 +1,7 @@ import { DEFAULT_CSS_PREFIX_KEY } from '@/core'; import { createInstance } from './createInstance'; -export { extractStyle } from './extractStyle'; +export { extractStaticStyle } from './extractStaticStyle'; export { setupStyled } from './setupStyled'; export { createInstance }; diff --git a/tests/functions/extractStyle.test.ts b/tests/functions/extractStaticStyle.test.ts similarity index 86% rename from tests/functions/extractStyle.test.ts rename to tests/functions/extractStaticStyle.test.ts index 485df1ab..1d7523d6 100644 --- a/tests/functions/extractStyle.test.ts +++ b/tests/functions/extractStaticStyle.test.ts @@ -1,5 +1,5 @@ import createCache from '@emotion/cache'; -import { extractStyle } from 'antd-style'; +import { extractStaticStyle } from 'antd-style'; describe('extractStyle', () => { const html = '
Hello World
'; @@ -14,7 +14,7 @@ describe('extractStyle', () => { }); it('should return an array of StyleItem', () => { - const result = extractStyle(html); + const result = extractStaticStyle(html); expect(Array.isArray(result)).toBe(true); expect(result[0]).toHaveProperty('key'); @@ -25,7 +25,7 @@ describe('extractStyle', () => { }); it('should create correct style tag for each cache', () => { - const result = extractStyle(html); + const result = extractStaticStyle(html); expect(result[0].tag).toMatch(//); expect(result[1].tag).toMatch(//);