Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: avoid rapid polling while fetching teams in selector (#5485)
Nivedinaa1583763a6f
diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vueindex 7c7668293..11ac0b699 100644--- a/packages/hoppscotch-common/src/components/app/Header.vue+++ b/packages/hoppscotch-common/src/components/app/Header.vue@@ -203,7 +203,7 @@class="!focus-visible:text-blue-600 !hover:text-blue-600 h-8 rounded border border-blue-600/25 bg-blue-500/10 pr-8 !text-blue-500 hover:border-blue-600/20 hover:bg-blue-600/20 focus-visible:border-blue-600/20 focus-visible:bg-blue-600/20"/></HoppSmartSelectWrapper>- <template #content="{ hide }">+ <template #content="{ hide, state }"><divref="accountActions"class="flex flex-col focus:outline-none"@@ -211,7 +211,7 @@@keyup.escape="hide()"@click="hide()">- <WorkspaceSelector />+ <WorkspaceSelector :state="state" /></div></template></tippy>diff --git a/packages/hoppscotch-common/src/components/workspace/Selector.vue b/packages/hoppscotch-common/src/components/workspace/Selector.vueindex 061fa8c3b..c511f32d7 100644--- a/packages/hoppscotch-common/src/components/workspace/Selector.vue+++ b/packages/hoppscotch-common/src/components/workspace/Selector.vue@@ -1,5 +1,5 @@<template>- <div ref="rootEl">+ <div class="flex flex-col"><div class="flex flex-col"><div class="flex flex-col"><HoppSmartItem@@ -81,6 +81,7 @@/></div></template>+<script setup lang="ts">import { computed, ref, watch } from "vue"import { useReadonlyStream } from "~/composables/stream"@@ -96,11 +97,16 @@ import { useLocalState } from "~/newstore/localstate"import { defineActionHandler, invokeAction } from "~/helpers/actions"import { WorkspaceService } from "~/services/workspace.service"import { useService } from "dioc/vue"-import { useElementVisibility, useIntervalFn } from "@vueuse/core"+import { useIntervalFn, watchDebounced } from "@vueuse/core"+import { TippyState } from "~/modules/tippy"const t = useI18n()const colorMode = useColorMode()+const props = defineProps<{+ state: TippyState | null+}>()+const showModalAdd = ref(false)const currentUser = useReadonlyStream(@@ -116,27 +122,35 @@ const teamListAdapterError = useReadonlyStream(teamListadapter.error$, null)const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID")const teamListFetched = ref(false)-const rootEl = ref<HTMLElement>()-const elVisible = useElementVisibility(rootEl)--const { pause: pauseListPoll, resume: resumeListPoll } = useIntervalFn(() => {- if (teamListadapter.isInitialized) {- teamListadapter.fetchList()- }-}, 10000)--watch(- elVisible,+const {+ pause: pauseListPoll,+ resume: resumeListPoll,+ isActive: isListPolling,+} = useIntervalFn(() => {- if (elVisible.value) {+ if (teamListadapter.isInitialized) {teamListadapter.fetchList()+ }+ },+ 10000,+ { immediate: false }+)- resumeListPoll()+// A debounced watcher to avoid rapid polling when component is mounted.+// only poll when the component is visible and pause when not visible.+watchDebounced(+ () => props.state?.isVisible,+ (isVisible) => {+ if (isVisible) {+ if (!isListPolling.value) {+ teamListadapter.fetchList()+ resumeListPoll()+ }} else {pauseListPoll()}},- { immediate: true }+ { debounce: 200 })watch(myTeams, (teams) => {diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts b/packages/hoppscotch-common/src/helpers/import-export/import/hopp.tsindex f949fbf8a..4168f8eb1 100644--- a/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts+++ b/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts@@ -5,7 +5,7 @@ import {getDefaultRESTRequest,translateToNewRESTCollection,HoppGQLRequest,- translateToNewGQLCollection+ translateToNewGQLCollection,} from "@hoppscotch/data"import * as A from "fp-ts/Array"import * as O from "fp-ts/Option"diff --git a/packages/hoppscotch-common/src/modules/tippy.ts b/packages/hoppscotch-common/src/modules/tippy.tsindex 72a36fa5e..e790d4270 100644--- a/packages/hoppscotch-common/src/modules/tippy.ts+++ b/packages/hoppscotch-common/src/modules/tippy.ts@@ -6,6 +6,14 @@ import "tippy.js/animations/scale-subtle.css"import "tippy.js/dist/border.css"import "tippy.js/dist/svg-arrow.css"+export type TippyState = {+ isEnabled: boolean+ isVisible: boolean+ isDestroyed: boolean+ isMounted: boolean+ isShown: boolean+}+export default <HoppModule>{onVueAppInit(app) {app.use(VueTippy)diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.tsindex 088ee4fbc..55e7ce04d 100644--- a/packages/hoppscotch-common/src/newstore/collections.ts+++ b/packages/hoppscotch-common/src/newstore/collections.ts@@ -8,7 +8,7 @@ import {HoppRESTHeaders,HoppRESTRequest,makeCollection,- GQLHeader+ GQLHeader,} from "@hoppscotch/data"import { cloneDeep } from "lodash-es"import { pluck } from "rxjs/operators"diff --git a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.tsindex 8d807bb73..d33a01ca1 100644--- a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts+++ b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts@@ -1,11 +1,11 @@import { Service } from "dioc"import { markRaw } from "vue"-import {- body,- relayRequestToNativeAdapter,+import {+ body,+ relayRequestToNativeAdapter,RelayRequest,RelayResponse,- RelayCapabilities+ RelayCapabilities,} from "@hoppscotch/kernel"import * as E from "fp-ts/Either"import { pipe } from "fp-ts/function"diff --git a/packages/hoppscotch-common/src/services/team-collection.service.ts b/packages/hoppscotch-common/src/services/team-collection.service.tsindex 2796499cf..0fcca76f5 100644--- a/packages/hoppscotch-common/src/services/team-collection.service.ts+++ b/packages/hoppscotch-common/src/services/team-collection.service.ts@@ -1059,6 +1059,15 @@ export class TeamCollectionsService extends Service<void> {collections.forEach((coll) => this.entityIDs.add(`collection-${coll.id}`))requests.forEach((req) => this.entityIDs.add(`request-${req.id}`))+ this.collections.value = [...tree]+ } catch (error) {+ console.error(`Error expanding collection ${collectionID}:`, error)++ // Set empty arrays instead of leaving as null to prevent future expansion attempts+ // This prevents the infinite loop by ensuring the collection is marked as expanded+ collection.children = []+ collection.requests = []+this.collections.value = [...tree]} finally {this.loadingCollections.value = this.loadingCollections.value.filter(