@@ -26,7 +26,7 @@ export const initializeComponent = async (
26
26
cmpMeta : d . ComponentRuntimeMeta ,
27
27
hmrVersionId ?: string ,
28
28
) => {
29
- let Cstr : any ;
29
+ let Cstr : d . ComponentConstructor | undefined ;
30
30
// initializeComponent
31
31
if ( ( hostRef . $flags$ & HOST_FLAGS . hasInitializedComponent ) === 0 ) {
32
32
// Let the runtime know that the component has been initialized
@@ -37,17 +37,19 @@ export const initializeComponent = async (
37
37
// lazy loaded components
38
38
// request the component's implementation to be
39
39
// wired up with the host element
40
- Cstr = loadModule ( cmpMeta , hostRef , hmrVersionId ) ;
41
- if ( Cstr . then ) {
40
+ const CstrImport = loadModule ( cmpMeta , hostRef , hmrVersionId ) ;
41
+ if ( CstrImport && ' then' in CstrImport ) {
42
42
// Await creates a micro-task avoid if possible
43
43
const endLoad = uniqueTime (
44
44
`st:load:${ cmpMeta . $tagName$ } :${ hostRef . $modeName$ } ` ,
45
45
`[Stencil] Load module for <${ cmpMeta . $tagName$ } >` ,
46
46
) ;
47
- Cstr = await Cstr ;
47
+ Cstr = await CstrImport ;
48
48
endLoad ( ) ;
49
+ } else {
50
+ Cstr = CstrImport as d . ComponentConstructor | undefined ;
49
51
}
50
- if ( ( BUILD . isDev || BUILD . isDebug ) && ! Cstr ) {
52
+ if ( ! Cstr ) {
51
53
throw new Error ( `Constructor for "${ cmpMeta . $tagName$ } #${ hostRef . $modeName$ } " was not found` ) ;
52
54
}
53
55
if ( BUILD . member && ! Cstr . isProxied ) {
@@ -96,12 +98,16 @@ export const initializeComponent = async (
96
98
customElements . whenDefined ( cmpMeta . $tagName$ ) . then ( ( ) => ( hostRef . $flags$ |= HOST_FLAGS . isWatchReady ) ) ;
97
99
}
98
100
99
- if ( BUILD . style && Cstr . style ) {
101
+ if ( BUILD . style && Cstr && Cstr . style ) {
100
102
// this component has styles but we haven't registered them yet
101
103
let style = Cstr . style ;
102
104
103
105
if ( BUILD . mode && typeof style !== 'string' ) {
104
- style = style [ ( hostRef . $modeName$ = computeMode ( elm ) ) ] ;
106
+ hostRef . $modeName$ = computeMode ( elm ) as string | undefined ;
107
+ if ( hostRef . $modeName$ ) {
108
+ style = style [ hostRef . $modeName$ ] ;
109
+ }
110
+
105
111
if ( BUILD . hydrateServerSide && hostRef . $modeName$ ) {
106
112
elm . setAttribute ( 's-mode' , hostRef . $modeName$ ) ;
107
113
}
0 commit comments