diff --git a/packages/devtools/client/app.vue b/packages/devtools/client/app.vue index 07fee6dda2..25ae3b03f5 100644 --- a/packages/devtools/client/app.vue +++ b/packages/devtools/client/app.vue @@ -6,7 +6,7 @@ import { computed, onMounted, watch, watchEffect } from 'vue' import { getColorMode, showConnectionWarning, useClient, useInjectionClient } from '~/composables/client' import { devAuthToken, isDevAuthed } from '~/composables/dev-auth' import { useCopy } from '~/composables/editor' -import { rpc } from '~/composables/rpc' +import { rpc, WS_DEBOUNCE_TIME } from '~/composables/rpc' import { registerCommands } from '~/composables/state-commands' import { splitScreenAvailable, splitScreenEnabled } from '~/composables/storage' import { useSchemaInput } from './composables/state-schema' @@ -45,6 +45,27 @@ const route = useRoute() const colorMode = getColorMode() const isUtilityView = computed(() => route.path.startsWith('/__') || route.path === '/') const waiting = computed(() => !client.value && !showConnectionWarning.value) +const showDisconnectIndicator = ref(false) + +if (wsConnectedOnce.value) { + // debounce one time to avoid showing the indicator on first load of the app + onConnected() +} +else { + // watch for connection and show the indicator if it was connected at least once + const stop = watch(wsConnectedOnce, (val) => { + if (val) { + onConnected() + stop() + } + }) +} + +function onConnected() { + setTimeout(() => { + showDisconnectIndicator.value = true + }, WS_DEBOUNCE_TIME) +} watch( () => client.value?.app.colorMode.value, @@ -153,7 +174,7 @@ registerCommands(() => [ - +
diff --git a/packages/devtools/client/composables/rpc.ts b/packages/devtools/client/composables/rpc.ts index 007e2dc73d..75784617d3 100644 --- a/packages/devtools/client/composables/rpc.ts +++ b/packages/devtools/client/composables/rpc.ts @@ -4,9 +4,11 @@ import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client' import { useDebounce } from '@vueuse/core' import { ref, shallowRef } from 'vue' +export const WS_DEBOUNCE_TIME = 2000 +export const wsConnectedOnce = ref(false) export const wsConnecting = ref(true) export const wsError = shallowRef() -export const wsConnectingDebounced = useDebounce(wsConnecting, 2000) +export const wsConnectingDebounced = useDebounce(wsConnecting, WS_DEBOUNCE_TIME) export const clientFunctions = { // will be added in setup/client-rpc.ts @@ -71,6 +73,7 @@ async function connectDevToolsRpc(): Promise { // eslint-disable-next-line no-console console.log('[nuxt-devtools] Connected to Vite DevTools RPC') wsConnecting.value = false + wsConnectedOnce.value = true return client }