Skip to content

Commit

Permalink
♻️ feat: 将 extractStyle 改名为 extractStaticStyle ,与 antd cssinjs 的错开
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 15, 2023
1 parent 4af15f4 commit 89f17dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import createEmotionServer from '@emotion/server/create-instance';
/**
* 表示一个样式项
*/
interface StyleItem {
export interface StyleItem {
/**
* @title 键值
*/
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/index.ts
Original file line number Diff line number Diff line change
@@ -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 };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createCache from '@emotion/cache';
import { extractStyle } from 'antd-style';
import { extractStaticStyle } from 'antd-style';

describe('extractStyle', () => {
const html = '<div>Hello World</div>';
Expand All @@ -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');
Expand All @@ -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(/<style.*data-emotion="test.*>/);
expect(result[1].tag).toMatch(/<style.*data-emotion="cache.*>/);
Expand Down

0 comments on commit 89f17dc

Please sign in to comment.