Skip to content

Commit dd549f3

Browse files
authored
Merge pull request #24 from CodinGame/fix-single-tab-feature
Fix single active tab feature
2 parents dd0a8d8 + e08c9ad commit dd549f3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/LanguageClient.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ function LanguageClient ({
7878

7979
useEffect(() => {
8080
languageClientCount++
81+
// As soon as a new language client is requested and we have a focus, let's become the active tab
8182
if (window.document.hasFocus()) {
8283
writeStorage(ACTIVE_TAB_LOCAL_STORAGE_KEY, currentTab)
8384
}
85+
return () => {
86+
languageClientCount--
87+
}
88+
}, [])
8489

90+
useEffect(() => {
8591
setWillShutdown(false)
8692

8793
if (shouldShutdownLanguageClientForInactivity || shouldShutdownLanguageClientAsNotActiveTab) {
@@ -105,7 +111,6 @@ function LanguageClient ({
105111
})
106112

107113
return () => {
108-
languageClientCount--
109114
errorDisposable.dispose()
110115
statusChangeDisposable.dispose()
111116
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)