Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: The newly added group name for the VariableAggregator operator cannot be found. (#19440)

balibabu977f1a9ab48f
diff --git a/web/src/pages/agent/form/variable-aggregator-form/index.tsx b/web/src/pages/agent/form/variable-aggregator-form/index.tsx
index 7b46e50a7f..9228077be7 100644
--- a/web/src/pages/agent/form/variable-aggregator-form/index.tsx
+++ b/web/src/pages/agent/form/variable-aggregator-form/index.tsx
@@ -5,7 +5,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { memo, useCallback } from 'react';
import { useFieldArray, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
-import { initialDataOperationsValues } from '../../constant';
+import { initialVariableAggregatorValues } from '../../constant';
import { useFormValues } from '../../hooks/use-form-values';
import { INextOperatorForm } from '../../interface';
import useGraphStore from '../../store';
@@ -20,13 +20,12 @@ function VariableAggregatorForm({ node }: INextOperatorForm) {
const { t } = useTranslation();
const getNode = useGraphStore((state) => state.getNode);
- const defaultValues = useFormValues(initialDataOperationsValues, node);
+ const defaultValues = useFormValues(initialVariableAggregatorValues, node);
const form = useForm<VariableAggregatorFormSchemaType>({
defaultValues: defaultValues,
mode: 'onChange',
resolver: zodResolver(FormSchema),
- shouldUnregister: true,
});
const { fields, remove, append } = useFieldArray({
diff --git a/web/src/pages/agent/form/variable-aggregator-form/use-watch-change.ts b/web/src/pages/agent/form/variable-aggregator-form/use-watch-change.ts
index 61903436ac..20230ba783 100644
--- a/web/src/pages/agent/form/variable-aggregator-form/use-watch-change.ts
+++ b/web/src/pages/agent/form/variable-aggregator-form/use-watch-change.ts
@@ -1,3 +1,4 @@
+import { isEqual } from 'lodash';
import { useEffect } from 'react';
import { UseFormReturn, useWatch } from 'react-hook-form';
import useGraphStore from '../../store';
@@ -8,24 +9,34 @@ export function useWatchFormChange(
form?: UseFormReturn<VariableAggregatorFormSchemaType>,
) {
const values = useWatch({ control: form?.control });
- const { replaceNodeForm } = useGraphStore((state) => state);
+ const { getNode, replaceNodeForm } = useGraphStore((state) => state);
useEffect(() => {
- if (id && form?.formState.isDirty) {
- const outputs = values.groups?.reduce(
- (pre, cur) => {
- if (cur.group_name) {
- pre[cur.group_name] = {
- type: cur.type,
- };
- }
+ if (!id) {
+ return;
+ }
+
+ const outputs = values.groups?.reduce(
+ (pre, cur) => {
+ if (cur.group_name) {
+ pre[cur.group_name] = {
+ type: cur.type,
+ };
+ }
+
+ return pre;
+ },
+ {} as Record<string, Record<string, any>>,
+ );
- return pre;
- },
- {} as Record<string, Record<string, any>>,
- );
+ const nextValues = { ...values, outputs: outputs ?? {} };
- replaceNodeForm(id, { ...values, outputs: outputs ?? {} });
+ // Gate on divergence from the store rather than formState.isDirty:
+ // isDirty compares against the mount-time defaultValues snapshot, so
+ // returning to it (add a group, then remove it) reads as "clean" and
+ // the deletion would never reach the store.
+ if (!isEqual(getNode(id)?.data.form, nextValues)) {
+ replaceNodeForm(id, nextValues);
}
- }, [form?.formState.isDirty, id, replaceNodeForm, values]);
+ }, [getNode, id, replaceNodeForm, values]);
}