From f115c4ab8ecd4d2250decd1cd39b64ef19538551 Mon Sep 17 00:00:00 2001
From: Nivedin <53208152+nivedin@users.noreply.github.com>
Date: Thu, 22 Aug 2024 22:40:21 +0530
Subject: [PATCH] fix: persist request execution context between tabs (#4284)
---
.../src/components/http/Request.vue | 19 ++++++++++++-------
.../src/helpers/rest/document.ts | 5 +++++
.../persistence/validation-schemas/index.ts | 1 +
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue
index 4b6e91f15..e486f1a4b 100644
--- a/packages/hoppscotch-common/src/components/http/Request.vue
+++ b/packages/hoppscotch-common/src/components/http/Request.vue
@@ -70,9 +70,11 @@
:title="`${t(
'action.send'
)} ${getSpecialKey()}↩`"
- :label="`${!loading ? t('action.send') : t('action.cancel')}`"
+ :label="`${
+ !isTabResponseLoading ? t('action.send') : t('action.cancel')
+ }`"
class="min-w-[5rem] flex-1 rounded-r-none"
- @click="!loading ? newSendRequest() : cancelRequest()"
+ @click="!isTabResponseLoading ? newSendRequest() : cancelRequest()"
/>
tab.value.document.response?.type === "loading"
+)
+
const showCurlImportModal = ref(false)
const showCodegenModal = ref(false)
const showSaveRequestModal = ref(false)
@@ -318,8 +324,6 @@ const saveRequestAction = ref(null)
const history = useReadonlyStream(restHistory$, [])
-const requestCancelFunc: Ref<(() => void) | null> = ref(null)
-
const userHistories = computed(() => {
return history.value.map((history) => history.request.endpoint).slice(0, 10)
})
@@ -351,7 +355,8 @@ const newSendRequest = async () => {
const [cancel, streamPromise] = runRESTRequest$(tab)
const streamResult = await streamPromise
- requestCancelFunc.value = cancel
+ tab.value.document.cancelFunction = cancel
+
if (E.isRight(streamResult)) {
subscribeToStream(
streamResult.right,
@@ -441,7 +446,7 @@ onUnmounted(() => {
const cancelRequest = () => {
loading.value = false
- requestCancelFunc.value?.()
+ tab.value.document.cancelFunction?.()
updateRESTResponse(null)
}
diff --git a/packages/hoppscotch-common/src/helpers/rest/document.ts b/packages/hoppscotch-common/src/helpers/rest/document.ts
index afc8e4ff4..9d75180c6 100644
--- a/packages/hoppscotch-common/src/helpers/rest/document.ts
+++ b/packages/hoppscotch-common/src/helpers/rest/document.ts
@@ -87,4 +87,9 @@ export type HoppRESTDocument = {
* (if any)
*/
inheritedProperties?: HoppInheritedProperty
+
+ /**
+ * The function responsible for cancelling the tab request call
+ */
+ cancelFunction?: () => void
}
diff --git a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
index 359aef4b9..fca7b31c4 100644
--- a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
+++ b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
@@ -539,6 +539,7 @@ export const REST_TAB_STATE_SCHEMA = z
responseTabPreference: z.optional(z.string()),
optionTabPreference: z.optional(z.enum(validRestOperations)),
inheritedProperties: z.optional(HoppInheritedPropertySchema),
+ cancelFunction: z.optional(z.function()),
})
.strict(),
})