Skip to content

Commit

Permalink
🐛 fix: 修正 createInstance 的 container 插入位置制定无效的问题
Browse files Browse the repository at this point in the history
close #47
  • Loading branch information
arvinxx committed Apr 23, 2023
1 parent d6de186 commit c0b00c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/factories/createStyleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface StyleProviderProps
interface DefaultProps {
prefix: string;
speedy?: boolean;
container?: Node;
}

export const createStyleProvider = (
Expand All @@ -48,7 +49,7 @@ export const createStyleProvider = (
prefix = defaultProps?.prefix || DEFAULT_CSS_PREFIX_KEY,
speedy = defaultProps?.speedy,
getStyleManager,
container,
container = defaultProps?.container,
nonce,
insertionPoint,
stylisPlugins,
Expand Down
10 changes: 9 additions & 1 deletion src/functions/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface CreateOptions<T> {
* @default false
*/
speedy?: boolean;

container?: Node;
/**
* 默认的自定义 Token
*/
Expand All @@ -57,7 +59,12 @@ export interface CreateOptions<T> {
export const createInstance = <T = any>(options: CreateOptions<T>) => {
const defaultKey = options.key || 'css';

const emotion = createEmotion({ key: defaultKey, speedy: options.speedy });
// TODO: 此处的 emotion 应该是 emotion context 中的 emotion,需要允许外部通过 Provider 进行修改
const emotion = createEmotion({
key: defaultKey,
speedy: options.speedy,
container: options.container,
});

// 将 cache 存到一个全局
cacheManager.add(emotion.cache);
Expand Down Expand Up @@ -105,6 +112,7 @@ export const createInstance = <T = any>(options: CreateOptions<T>) => {
const StyleProvider = createStyleProvider(EmotionContext, {
speedy: options.speedy,
prefix: defaultKey,
container: options.container,
});

return {
Expand Down

0 comments on commit c0b00c3

Please sign in to comment.