fix: 修复ConfigForm和EmbeddingConfigForm组件watch死循环导致内存溢出 [AC-AISVC-50]

This commit is contained in:
MerCry 2026-02-26 12:30:04 +08:00
parent 6c16132557
commit 3f1f4cd98d
2 changed files with 14 additions and 0 deletions

View File

@ -92,6 +92,7 @@ const emit = defineEmits<{
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const formData = ref<Record<string, any>>({}) const formData = ref<Record<string, any>>({})
const isUpdating = ref(false)
const schemaProperties = computed(() => { const schemaProperties = computed(() => {
return props.schema?.properties || {} return props.schema?.properties || {}
@ -174,6 +175,7 @@ const initFormData = () => {
watch( watch(
() => props.modelValue, () => props.modelValue,
(newVal) => { (newVal) => {
if (isUpdating.value) return
if (JSON.stringify(newVal) !== JSON.stringify(formData.value)) { if (JSON.stringify(newVal) !== JSON.stringify(formData.value)) {
initFormData() initFormData()
} }
@ -192,8 +194,13 @@ watch(
watch( watch(
formData, formData,
(val) => { (val) => {
if (isUpdating.value) return
if (JSON.stringify(val) !== JSON.stringify(props.modelValue)) { if (JSON.stringify(val) !== JSON.stringify(props.modelValue)) {
isUpdating.value = true
emit('update:modelValue', val) emit('update:modelValue', val)
Promise.resolve().then(() => {
isUpdating.value = false
})
} }
}, },
{ deep: true } { deep: true }

View File

@ -92,6 +92,7 @@ const emit = defineEmits<{
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const formData = ref<Record<string, any>>({}) const formData = ref<Record<string, any>>({})
const isUpdating = ref(false)
const schemaProperties = computed(() => { const schemaProperties = computed(() => {
return props.schema?.properties || {} return props.schema?.properties || {}
@ -174,6 +175,7 @@ const initFormData = () => {
watch( watch(
() => props.modelValue, () => props.modelValue,
(newVal) => { (newVal) => {
if (isUpdating.value) return
if (JSON.stringify(newVal) !== JSON.stringify(formData.value)) { if (JSON.stringify(newVal) !== JSON.stringify(formData.value)) {
initFormData() initFormData()
} }
@ -192,8 +194,13 @@ watch(
watch( watch(
formData, formData,
(val) => { (val) => {
if (isUpdating.value) return
if (JSON.stringify(val) !== JSON.stringify(props.modelValue)) { if (JSON.stringify(val) !== JSON.stringify(props.modelValue)) {
isUpdating.value = true
emit('update:modelValue', val) emit('update:modelValue', val)
Promise.resolve().then(() => {
isUpdating.value = false
})
} }
}, },
{ deep: true } { deep: true }