@@ -47,7 +47,13 @@ export const registerStyle = (scopeId: string, cssText: string, allowCS: boolean
47
47
* @param mode an optional current mode
48
48
* @returns the scope ID for the component of interest
49
49
*/
50
- export const addStyle = ( styleContainerNode : any , cmpMeta : d . ComponentRuntimeMeta , mode ?: string ) => {
50
+ export const addStyle = (
51
+ styleContainerNode : Element | Document | ShadowRoot ,
52
+ cmpMeta : d . ComponentRuntimeMeta ,
53
+ mode ?: string ,
54
+ ) => {
55
+ const styleContainerDocument = styleContainerNode as Document ;
56
+ const styleContainerShadowRoot = styleContainerNode as ShadowRoot ;
51
57
const scopeId = getScopeId ( cmpMeta , mode ) ;
52
58
const style = styles . get ( scopeId ) ;
53
59
@@ -60,7 +66,7 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
60
66
61
67
if ( style ) {
62
68
if ( typeof style === 'string' ) {
63
- styleContainerNode = styleContainerNode . head || styleContainerNode ;
69
+ styleContainerNode = styleContainerDocument . head || ( styleContainerNode as HTMLElement ) ;
64
70
let appliedStyles = rootAppliedStyles . get ( styleContainerNode ) ;
65
71
let styleElm ;
66
72
if ( ! appliedStyles ) {
@@ -69,7 +75,7 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
69
75
if ( ! appliedStyles . has ( scopeId ) ) {
70
76
if (
71
77
BUILD . hydrateClientSide &&
72
- styleContainerNode . host &&
78
+ styleContainerShadowRoot . host &&
73
79
( styleElm = styleContainerNode . querySelector ( `[${ HYDRATED_STYLE_ID } ="${ scopeId } "]` ) )
74
80
) {
75
81
// This is only happening on native shadow-dom, do not needs CSS var shim
@@ -100,8 +106,8 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
100
106
appliedStyles . add ( scopeId ) ;
101
107
}
102
108
}
103
- } else if ( BUILD . constructableCSS && ! styleContainerNode . adoptedStyleSheets . includes ( style ) ) {
104
- styleContainerNode . adoptedStyleSheets = [ ...styleContainerNode . adoptedStyleSheets , style ] ;
109
+ } else if ( BUILD . constructableCSS && ! styleContainerDocument . adoptedStyleSheets . includes ( style ) ) {
110
+ styleContainerDocument . adoptedStyleSheets = [ ...styleContainerDocument . adoptedStyleSheets , style ] ;
105
111
}
106
112
}
107
113
return scopeId ;
@@ -119,7 +125,7 @@ export const attachStyles = (hostRef: d.HostRef) => {
119
125
const flags = cmpMeta . $flags$ ;
120
126
const endAttachStyles = createTime ( 'attachStyles' , cmpMeta . $tagName$ ) ;
121
127
const scopeId = addStyle (
122
- BUILD . shadowDom && supportsShadow && elm . shadowRoot ? elm . shadowRoot : elm . getRootNode ( ) ,
128
+ BUILD . shadowDom && supportsShadow && elm . shadowRoot ? elm . shadowRoot : ( elm . getRootNode ( ) as ShadowRoot ) ,
123
129
cmpMeta ,
124
130
hostRef . $modeName$ ,
125
131
) ;
0 commit comments