Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(frontend): infinite loop in InstanceForm (#4588)

Liu Ji8d88827c1a69
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 077def9f5c..2e80124735 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -476,7 +476,7 @@ import { computed, reactive, PropType } from "vue";
import EnvironmentSelect from "../components/EnvironmentSelect.vue";
import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";
import { SslCertificateForm } from "./InstanceForm";
-import { hasWorkspacePermission } from "../utils";
+import { clearObject, hasWorkspacePermission } from "../utils";
import {
InstancePatch,
DataSourceType,
@@ -814,7 +814,11 @@ const updateInstanceDataSource = (dataSource: EditDataSource) => {
delete newValue.sslKey;
}
- state.instance.dataSourceList[index] = newValue;
+ // Won't modify the obj ref, but modify its fields in-place, to avoid
+ // infinite loop caused by vue's reactivity.
+ const oldValue = state.instance.dataSourceList[index];
+ clearObject(oldValue);
+ Object.assign(oldValue, newValue);
};
const handleCreateDataSource = (type: DataSourceType) => {
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index 4b9d0a37e5..81998cbb08 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -200,3 +200,9 @@ export function semverCompare(v1: string, v2: string) {
return semver.gt(formatedV1, formatedV2);
}
+
+export function clearObject(obj: any) {
+ const keys = Object.keys(obj);
+ keys.forEach((key) => delete obj[key]);
+ return obj;
+}