1
1
import type { ReactiveControllerHost } from '@lit/reactive-element' ;
2
-
3
2
import type Atmosphere from 'atmosphere.js' ;
4
-
5
3
import type { Subscription } from './Connect.js' ;
6
4
import { getCsrfTokenHeadersForEndpointRequest } from './CsrfUtils.js' ;
7
5
import {
@@ -75,14 +73,6 @@ type EndpointInfo = {
75
73
reconnect ?( ) : ActionOnLostSubscription | void ;
76
74
} ;
77
75
78
- interface ImportMetaEnv {
79
- readonly SW_CONTEXT : boolean ;
80
- }
81
-
82
- interface ImportMeta {
83
- readonly env : ImportMetaEnv ;
84
- }
85
-
86
76
/**
87
77
* A representation of the underlying persistent network connection used for subscribing to Flux type endpoint methods.
88
78
*/
@@ -101,16 +91,16 @@ export class FluxConnection extends EventTarget {
101
91
102
92
constructor ( connectPrefix : string , atmosphereOptions ?: Partial < Atmosphere . Request > ) {
103
93
super ( ) ;
104
- // @ts -expect-error - vite environment variable
105
- const meta : ImportMeta = import . meta ;
106
- if ( ! meta . env . SW_CONTEXT ) {
107
- ( async ( ) => {
108
- atmosphere = await import ( 'atmosphere.js' ) ;
109
- this . #connectWebsocket ( connectPrefix . replace ( / c o n n e c t $ / u , '' ) , atmosphereOptions ?? { } ) ;
110
- } ) ( ) . catch ( ( e ) => {
111
- // eslint-disable-next-line no-console
112
- console . error ( 'Failed to load atmosphere.js ' , e ) ;
113
- } ) ;
94
+ if ( ! import . meta . env [ 'VITE_SW_CONTEXT' ] ) {
95
+ import ( 'atmosphere.js' )
96
+ . then ( ( module ) => {
97
+ atmosphere = module . default ;
98
+ this . #connectWebsocket ( connectPrefix . replace ( / c o n n e c t $ / u , '' ) , atmosphereOptions ?? { } ) ;
99
+ } )
100
+ . catch ( ( error ) => {
101
+ // eslint-disable-next-line no-console
102
+ console . error ( 'Failed to load atmosphere' , error ) ;
103
+ } ) ;
114
104
}
115
105
}
116
106
0 commit comments