Browse Source

fix: shared references on saveRequest causing overwrite fixes #1992

Andrew Bastin 3 years ago
parent
commit
4d6d30c92b
1 changed files with 6 additions and 1 deletions
  1. 6 1
      packages/hoppscotch-app/components/collections/SaveRequest.vue

+ 6 - 1
packages/hoppscotch-app/components/collections/SaveRequest.vue

@@ -60,6 +60,7 @@
 <script setup lang="ts">
 <script setup lang="ts">
 import { reactive, ref, watch } from "@nuxtjs/composition-api"
 import { reactive, ref, watch } from "@nuxtjs/composition-api"
 import { HoppGQLRequest, isHoppRESTRequest } from "@hoppscotch/data"
 import { HoppGQLRequest, isHoppRESTRequest } from "@hoppscotch/data"
+import cloneDeep from "lodash/cloneDeep"
 import {
 import {
   editGraphqlRequest,
   editGraphqlRequest,
   editRESTRequest,
   editRESTRequest,
@@ -199,8 +200,12 @@ const saveRequestAs = async () => {
     return
     return
   }
   }
 
 
+  // Clone Deep because objects are shared by reference so updating
+  // just one bit will update other referenced shared instances
   const requestUpdated =
   const requestUpdated =
-    props.mode === "rest" ? getRESTRequest() : getGQLSession().request
+    props.mode === "rest"
+      ? cloneDeep(getRESTRequest())
+      : cloneDeep(getGQLSession().request)
 
 
   // // Filter out all REST file inputs
   // // Filter out all REST file inputs
   // if (this.mode === "rest" && requestUpdated.bodyParams) {
   // if (this.mode === "rest" && requestUpdated.bodyParams) {