@@ -4,7 +4,6 @@ import CacheEntity from './Cache';
44import type { Linter } from './linters/interface' ;
55import type { Transformer } from './transformers/interface' ;
66import { arrayType , booleanType , objectType , someType , stringType , withInstall } from '../type' ;
7- import initDefaultProps from '../props-util/initDefaultProps' ;
87export const ATTR_TOKEN = 'data-token-hash' ;
98export const ATTR_MARK = 'data-css-hash' ;
109export const ATTR_CACHE_PATH = 'data-cache-path' ;
@@ -25,7 +24,10 @@ export function createCache() {
2524 ( style as any ) [ CSS_IN_JS_INSTANCE ] = ( style as any ) [ CSS_IN_JS_INSTANCE ] || cssinjsInstanceId ;
2625
2726 // 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+ }
2931 } ) ;
3032
3133 // Deduplicate of moved styles
@@ -83,12 +85,16 @@ const defaultStyleContext: StyleContextProps = {
8385 defaultCache : true ,
8486 hashPriority : 'low' ,
8587} ;
88+ // fix: https://github.com/vueComponent/ant-design-vue/issues/6912
8689export const useStyleInject = ( ) => {
87- return inject ( StyleContextKey , shallowRef ( { ...defaultStyleContext } ) ) ;
90+ return inject ( StyleContextKey , shallowRef ( { ...defaultStyleContext , cache : createCache ( ) } ) ) ;
8891} ;
8992export const useStyleProvider = ( props : UseStyleProviderProps ) => {
9093 const parentContext = useStyleInject ( ) ;
91- const context = shallowRef < Partial < StyleContextProps > > ( { ...defaultStyleContext } ) ;
94+ const context = shallowRef < Partial < StyleContextProps > > ( {
95+ ...defaultStyleContext ,
96+ cache : createCache ( ) ,
97+ } ) ;
9298 watch (
9399 [ ( ) => unref ( props ) , parentContext ] ,
94100 ( ) => {
@@ -144,7 +150,7 @@ export const StyleProvider = withInstall(
144150 defineComponent ( {
145151 name : 'AStyleProvider' ,
146152 inheritAttrs : false ,
147- props : initDefaultProps ( styleProviderProps ( ) , defaultStyleContext ) ,
153+ props : styleProviderProps ( ) ,
148154 setup ( props , { slots } ) {
149155 useStyleProvider ( props ) ;
150156 return ( ) => slots . default ?.( ) ;
0 commit comments