@@ -2,6 +2,7 @@ import { ReactElement, useEffect, useRef, useState } from 'react'
2
2
import { createLanguageClientManager , LanguageClientId , StatusChangeEvent as WrapperStatusChangeEvent , LanguageClientManager , WillShutdownParams , Infrastructure , LanguageClientOptions , LanguageClientManagerOptions } from '@codingame/monaco-languageclient-wrapper'
3
3
import { useLocalStorage , writeStorage } from '@rehooks/local-storage'
4
4
import { v4 as uuidv4 } from 'uuid'
5
+ import { initializePromise } from '@codingame/monaco-editor-wrapper'
5
6
import useIsUserActive from './hooks/useIsUserActive'
6
7
import useShouldShutdownLanguageClient from './hooks/useShouldShutdownLanguageClient'
7
8
import { useLastVersion } from './hooks/useLastVersion'
@@ -59,6 +60,13 @@ function LanguageClient ({
59
60
60
61
const [ willShutdown , setWillShutdown ] = useState ( false )
61
62
const [ counter , setCounter ] = useState ( 1 )
63
+ const [ servicesReady , setServicesReady ] = useState ( false )
64
+ useEffect ( ( ) => {
65
+ void ( async ( ) => {
66
+ await initializePromise
67
+ setServicesReady ( true )
68
+ } ) ( )
69
+ } , [ ] )
62
70
63
71
const isUserActive = useIsUserActive ( userInactivityDelay )
64
72
const shouldShutdownLanguageClientForInactivity = useShouldShutdownLanguageClient ( isUserActive , userInactivityShutdownDelay )
@@ -88,6 +96,9 @@ function LanguageClient ({
88
96
} , [ ] )
89
97
90
98
useEffect ( ( ) => {
99
+ if ( ! servicesReady ) {
100
+ return
101
+ }
91
102
setWillShutdown ( false )
92
103
93
104
if ( shouldShutdownLanguageClientForInactivity || shouldShutdownLanguageClientAsNotActiveTab ) {
@@ -127,7 +138,7 @@ function LanguageClient ({
127
138
} )
128
139
} )
129
140
}
130
- } , [ id , counter , shouldShutdownLanguageClientForInactivity , onError , onDidChangeStatus , onWillShutdown , infrastructure , clientOptions , clientManagerOptions , shouldShutdownLanguageClientAsNotActiveTab ] )
141
+ } , [ id , counter , shouldShutdownLanguageClientForInactivity , onError , onDidChangeStatus , onWillShutdown , infrastructure , clientOptions , clientManagerOptions , shouldShutdownLanguageClientAsNotActiveTab , servicesReady ] )
131
142
132
143
return null
133
144
}
0 commit comments