@@ -2,6 +2,7 @@ import { ReactElement, useEffect, useRef, useState } from 'react'
22import { createLanguageClientManager , LanguageClientId , StatusChangeEvent as WrapperStatusChangeEvent , LanguageClientManager , WillShutdownParams , Infrastructure , LanguageClientOptions , LanguageClientManagerOptions } from '@codingame/monaco-languageclient-wrapper'
33import { useLocalStorage , writeStorage } from '@rehooks/local-storage'
44import { v4 as uuidv4 } from 'uuid'
5+ import { initializePromise } from '@codingame/monaco-editor-wrapper'
56import useIsUserActive from './hooks/useIsUserActive'
67import useShouldShutdownLanguageClient from './hooks/useShouldShutdownLanguageClient'
78import { useLastVersion } from './hooks/useLastVersion'
@@ -59,6 +60,13 @@ function LanguageClient ({
5960
6061 const [ willShutdown , setWillShutdown ] = useState ( false )
6162 const [ counter , setCounter ] = useState ( 1 )
63+ const [ servicesReady , setServicesReady ] = useState ( false )
64+ useEffect ( ( ) => {
65+ void ( async ( ) => {
66+ await initializePromise
67+ setServicesReady ( true )
68+ } ) ( )
69+ } , [ ] )
6270
6371 const isUserActive = useIsUserActive ( userInactivityDelay )
6472 const shouldShutdownLanguageClientForInactivity = useShouldShutdownLanguageClient ( isUserActive , userInactivityShutdownDelay )
@@ -88,6 +96,9 @@ function LanguageClient ({
8896 } , [ ] )
8997
9098 useEffect ( ( ) => {
99+ if ( ! servicesReady ) {
100+ return
101+ }
91102 setWillShutdown ( false )
92103
93104 if ( shouldShutdownLanguageClientForInactivity || shouldShutdownLanguageClientAsNotActiveTab ) {
@@ -127,7 +138,7 @@ function LanguageClient ({
127138 } )
128139 } )
129140 }
130- } , [ id , counter , shouldShutdownLanguageClientForInactivity , onError , onDidChangeStatus , onWillShutdown , infrastructure , clientOptions , clientManagerOptions , shouldShutdownLanguageClientAsNotActiveTab ] )
141+ } , [ id , counter , shouldShutdownLanguageClientForInactivity , onError , onDidChangeStatus , onWillShutdown , infrastructure , clientOptions , clientManagerOptions , shouldShutdownLanguageClientAsNotActiveTab , servicesReady ] )
131142
132143 return null
133144}
0 commit comments