Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(common): preserve currentValue for non-secret env variables on wire

James George9aabf0e538fc
diff --git a/packages/hoppscotch-common/src/helpers/__tests__/secretVariables.spec.ts b/packages/hoppscotch-common/src/helpers/__tests__/secretVariables.spec.ts
index 607fb2f0c..d770ee5c7 100644
--- a/packages/hoppscotch-common/src/helpers/__tests__/secretVariables.spec.ts
+++ b/packages/hoppscotch-common/src/helpers/__tests__/secretVariables.spec.ts
@@ -37,7 +37,7 @@ describe("stripSecretVariableValuesForWire", () => {
])
})
- it("keeps initialValue but clears currentValue for non-secret variables", () => {
+ it("keeps both initialValue and currentValue for non-secret variables", () => {
const result = stripSecretVariableValuesForWire([
{
key: "host",
@@ -51,7 +51,7 @@ describe("stripSecretVariableValuesForWire", () => {
{
key: "host",
initialValue: "https://api.example.com",
- currentValue: "",
+ currentValue: "https://staging.example.com",
secret: false,
},
])
diff --git a/packages/hoppscotch-common/src/helpers/secretVariables.ts b/packages/hoppscotch-common/src/helpers/secretVariables.ts
index 38f335190..e8658be3e 100644
--- a/packages/hoppscotch-common/src/helpers/secretVariables.ts
+++ b/packages/hoppscotch-common/src/helpers/secretVariables.ts
@@ -13,8 +13,14 @@ type SecretCapableVariable = {
}
/**
- * Clear `initialValue` for secrets and `currentValue` for all variables
- * before the wire write. Raw values live only in the local secret store.
+ * Strip raw values that must never reach the backend before the wire write.
+ *
+ * For SECRET variables we clear BOTH `initialValue` and `currentValue` — the
+ * secret value lives only in the local secret store (see #6279).
+ *
+ * For NON-SECRET variables `currentValue` is a normal, syncable value and
+ * MUST be preserved on the wire — otherwise environment / global-env updates
+ * persist an empty `currentValue` and the value is lost on reload.
*/
export const stripSecretVariableValuesForWire = <
T extends SecretCapableVariable,
@@ -24,14 +30,14 @@ export const stripSecretVariableValuesForWire = <
variables.map((v) => ({
...v,
initialValue: v.secret ? "" : v.initialValue,
- currentValue: "",
+ currentValue: v.secret ? "" : v.currentValue,
}))
/**
* Seed the local secret + currentValue stores from raw variables.
*
- * IMPORTANT: pass RAW (pre-strip) inputs. A stripped variable has empty
- * `initialValue` / `currentValue` and will persist as blank.
+ * IMPORTANT: pass RAW (pre-strip) inputs. A stripped SECRET variable has
+ * empty `initialValue` / `currentValue` and will persist as blank.
*
* ─── `??` vs `||` — read before "fixing" this ───
* Both branches below use `??` so an explicit `""` is preserved. This is
@@ -89,12 +95,11 @@ export const populateLocalStoresFromVariables = (
}
/**
- * Foreign-import convention normalizer for BOTH secret and non-secret
- * variables. The wire strip blanks `currentValue` for everything and (for
- * secrets) `initialValue`; non-secret `initialValue` is preserved. So a
- * Hoppscotch / Postman / Insomnia exported file lands with
- * `currentValue: ""` and (for non-secrets) `initialValue: "value"`. Promote
- * so the local stores see the imported value.
+ * Foreign-import convention normalizer for variables exported with
+ * `currentValue: ""` and the real value in `initialValue` — Postman /
+ * Insomnia format, plus legacy Hoppscotch exports from before non-secret
+ * `currentValue` was preserved on the wire. Promote so the local stores
+ * see the imported value.
*
* The global-env rehydration path bypasses this step intentionally — there
* `""` means "user deliberately cleared," not "value lives in initialValue."