Skip to content

Commit 73311b3

Browse files
author
Loïc Mangeonjean
committed
fix: wait for services to be ready
1 parent 8a309ac commit 73311b3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/LanguageClient.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ReactElement, useEffect, useRef, useState } from 'react'
22
import { createLanguageClientManager, LanguageClientId, StatusChangeEvent as WrapperStatusChangeEvent, LanguageClientManager, WillShutdownParams, Infrastructure, LanguageClientOptions, LanguageClientManagerOptions } from '@codingame/monaco-languageclient-wrapper'
33
import { useLocalStorage, writeStorage } from '@rehooks/local-storage'
44
import { v4 as uuidv4 } from 'uuid'
5+
import { initializePromise } from '@codingame/monaco-editor-wrapper'
56
import useIsUserActive from './hooks/useIsUserActive'
67
import useShouldShutdownLanguageClient from './hooks/useShouldShutdownLanguageClient'
78
import { 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

Comments
 (0)