1
1
import type { ReactiveControllerHost } from '@lit/reactive-element' ;
2
- import { ConnectionIndicator , ConnectionState } from '@vaadin/common-frontend' ;
2
+ import type * as CommonFrontendModule from '@vaadin/common-frontend' ;
3
3
import { getCsrfTokenHeadersForEndpointRequest } from './CsrfUtils.js' ;
4
4
import {
5
5
EndpointError ,
@@ -16,6 +16,11 @@ import {
16
16
} from './FluxConnection.js' ;
17
17
import type { VaadinGlobal } from './types.js' ;
18
18
19
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
20
+ const commonFrontendModule : Partial < typeof CommonFrontendModule > = globalThis . document
21
+ ? await import ( '@vaadin/common-frontend' )
22
+ : { } ;
23
+
19
24
const $wnd = globalThis as VaadinGlobal ;
20
25
21
26
$wnd . Vaadin ??= { } ;
@@ -291,21 +296,24 @@ export class ConnectClient {
291
296
this . atmosphereOptions = options . atmosphereOptions ;
292
297
}
293
298
294
- // add connection indicator to DOM
295
- ConnectionIndicator . create ( ) ;
296
-
297
- // Listen to browser online/offline events and update the loading indicator accordingly.
298
- // Note: if Flow.ts is loaded, it instead handles the state transitions.
299
- addEventListener ( 'online' , ( ) => {
300
- if ( ! isFlowLoaded ( ) && $wnd . Vaadin ?. connectionState ) {
301
- $wnd . Vaadin . connectionState . state = ConnectionState . CONNECTED ;
302
- }
303
- } ) ;
304
- addEventListener ( 'offline' , ( ) => {
305
- if ( ! isFlowLoaded ( ) && $wnd . Vaadin ?. connectionState ) {
306
- $wnd . Vaadin . connectionState . state = ConnectionState . CONNECTION_LOST ;
307
- }
308
- } ) ;
299
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
300
+ if ( globalThis . document ) {
301
+ // add connection indicator to DOM
302
+ commonFrontendModule . ConnectionIndicator ?. create ( ) ;
303
+
304
+ // Listen to browser online/offline events and update the loading indicator accordingly.
305
+ // Note: if Flow.ts is loaded, it instead handles the state transitions.
306
+ addEventListener ( 'online' , ( ) => {
307
+ if ( ! isFlowLoaded ( ) && $wnd . Vaadin ?. connectionState && commonFrontendModule . ConnectionState ) {
308
+ $wnd . Vaadin . connectionState . state = commonFrontendModule . ConnectionState . CONNECTED ;
309
+ }
310
+ } ) ;
311
+ addEventListener ( 'offline' , ( ) => {
312
+ if ( ! isFlowLoaded ( ) && $wnd . Vaadin ?. connectionState && commonFrontendModule . ConnectionState ) {
313
+ $wnd . Vaadin . connectionState . state = commonFrontendModule . ConnectionState . CONNECTION_LOST ;
314
+ }
315
+ } ) ;
316
+ }
309
317
}
310
318
311
319
/**
0 commit comments