Skip to content

Commit cf8d9c5

Browse files
authored
fix(devtools/client): debounce render of NDisconnectIndicator (#979)
1 parent 32563f0 commit cf8d9c5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

‎packages/devtools/client/app.vue‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { computed, onMounted, watch, watchEffect } from 'vue'
66
import { getColorMode, showConnectionWarning, useClient, useInjectionClient } from '~/composables/client'
77
import { devAuthToken, isDevAuthed } from '~/composables/dev-auth'
88
import { useCopy } from '~/composables/editor'
9-
import { rpc } from '~/composables/rpc'
9+
import { rpc, WS_DEBOUNCE_TIME } from '~/composables/rpc'
1010
import { registerCommands } from '~/composables/state-commands'
1111
import { splitScreenAvailable, splitScreenEnabled } from '~/composables/storage'
1212
import { useSchemaInput } from './composables/state-schema'
@@ -45,6 +45,27 @@ const route = useRoute()
4545
const colorMode = getColorMode()
4646
const isUtilityView = computed(() => route.path.startsWith('/__') || route.path === '/')
4747
const waiting = computed(() => !client.value && !showConnectionWarning.value)
48+
const showDisconnectIndicator = ref(false)
49+
50+
if (wsConnectedOnce.value) {
51+
// debounce one time to avoid showing the indicator on first load of the app
52+
onConnected()
53+
}
54+
else {
55+
// watch for connection and show the indicator if it was connected at least once
56+
const stop = watch(wsConnectedOnce, (val) => {
57+
if (val) {
58+
onConnected()
59+
stop()
60+
}
61+
})
62+
}
63+
64+
function onConnected() {
65+
setTimeout(() => {
66+
showDisconnectIndicator.value = true
67+
}, WS_DEBOUNCE_TIME)
68+
}
4869
4970
watch(
5071
() => client.value?.app.colorMode.value,
@@ -153,7 +174,7 @@ registerCommands(() => [
153174
<CommandPalette />
154175
<AuthConfirmDialog />
155176
</div>
156-
<DisconnectIndicator />
177+
<DisconnectIndicator v-if="showDisconnectIndicator" />
157178
<RestartDialogs />
158179
<div v-lazy-show="dataSchema">
159180
<LazyDataSchemaDrawer />

‎packages/devtools/client/composables/rpc.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
44
import { useDebounce } from '@vueuse/core'
55
import { ref, shallowRef } from 'vue'
66

7+
export const WS_DEBOUNCE_TIME = 2000
8+
export const wsConnectedOnce = ref(false)
79
export const wsConnecting = ref(true)
810
export const wsError = shallowRef<any>()
9-
export const wsConnectingDebounced = useDebounce(wsConnecting, 2000)
11+
export const wsConnectingDebounced = useDebounce(wsConnecting, WS_DEBOUNCE_TIME)
1012

1113
export const clientFunctions = {
1214
// will be added in setup/client-rpc.ts
@@ -71,6 +73,7 @@ async function connectDevToolsRpc(): Promise<DevToolsRpcClient> {
7173
// eslint-disable-next-line no-console
7274
console.log('[nuxt-devtools] Connected to Vite DevTools RPC')
7375
wsConnecting.value = false
76+
wsConnectedOnce.value = true
7477

7578
return client
7679
}

0 commit comments

Comments
 (0)