@@ -4,7 +4,6 @@ import CacheEntity from './Cache';
4
4
import type { Linter } from './linters/interface' ;
5
5
import type { Transformer } from './transformers/interface' ;
6
6
import { arrayType , booleanType , objectType , someType , stringType , withInstall } from '../type' ;
7
- import initDefaultProps from '../props-util/initDefaultProps' ;
8
7
export const ATTR_TOKEN = 'data-token-hash' ;
9
8
export const ATTR_MARK = 'data-css-hash' ;
10
9
export const ATTR_CACHE_PATH = 'data-cache-path' ;
@@ -25,7 +24,10 @@ export function createCache() {
25
24
( style as any ) [ CSS_IN_JS_INSTANCE ] = ( style as any ) [ CSS_IN_JS_INSTANCE ] || cssinjsInstanceId ;
26
25
27
26
// Not force move if no head
28
- document . head . insertBefore ( style , firstChild ) ;
27
+ // Not force move if no head
28
+ if ( ( style as any ) [ CSS_IN_JS_INSTANCE ] === cssinjsInstanceId ) {
29
+ document . head . insertBefore ( style , firstChild ) ;
30
+ }
29
31
} ) ;
30
32
31
33
// Deduplicate of moved styles
@@ -83,12 +85,16 @@ const defaultStyleContext: StyleContextProps = {
83
85
defaultCache : true ,
84
86
hashPriority : 'low' ,
85
87
} ;
88
+ // fix: https://github.com/vueComponent/ant-design-vue/issues/6912
86
89
export const useStyleInject = ( ) => {
87
- return inject ( StyleContextKey , shallowRef ( { ...defaultStyleContext } ) ) ;
90
+ return inject ( StyleContextKey , shallowRef ( { ...defaultStyleContext , cache : createCache ( ) } ) ) ;
88
91
} ;
89
92
export const useStyleProvider = ( props : UseStyleProviderProps ) => {
90
93
const parentContext = useStyleInject ( ) ;
91
- const context = shallowRef < Partial < StyleContextProps > > ( { ...defaultStyleContext } ) ;
94
+ const context = shallowRef < Partial < StyleContextProps > > ( {
95
+ ...defaultStyleContext ,
96
+ cache : createCache ( ) ,
97
+ } ) ;
92
98
watch (
93
99
[ ( ) => unref ( props ) , parentContext ] ,
94
100
( ) => {
@@ -144,7 +150,7 @@ export const StyleProvider = withInstall(
144
150
defineComponent ( {
145
151
name : 'AStyleProvider' ,
146
152
inheritAttrs : false ,
147
- props : initDefaultProps ( styleProviderProps ( ) , defaultStyleContext ) ,
153
+ props : styleProviderProps ( ) ,
148
154
setup ( props , { slots } ) {
149
155
useStyleProvider ( props ) ;
150
156
return ( ) => slots . default ?.( ) ;
0 commit comments