fix(LinkageRules): avoid to change observable object (#3538)

This commit is contained in:
Zeke Zhang 2024-02-21 11:22:47 +08:00 committed by GitHub
parent 65d1b41165
commit bb46697e71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View File

@ -149,7 +149,7 @@ const WithForm = (props: WithFormProps) => {
return result;
},
getSubscriber(action, field, rule, form, variables, localVariables),
getSubscriber(action, field, rule, variables, localVariables),
{ fireImmediately: true },
),
);
@ -229,7 +229,6 @@ function getSubscriber(
action: any,
field: any,
rule: any,
form: FormilyForm<any>,
variables: VariablesContextType,
localVariables: VariableOption[],
): (value: string, oldValue: string) => void {
@ -240,7 +239,6 @@ function getSubscriber(
value: action.value,
field,
condition: rule.condition,
values: form.values,
variables,
localVariables,
});
@ -251,7 +249,7 @@ function getSubscriber(
const fieldName = getFieldNameByOperator(action.operator);
// 防止重复赋值
if (!field.stateOfLinkageRules[fieldName]) {
if (!field.stateOfLinkageRules?.[fieldName]) {
return;
}

View File

@ -14,7 +14,6 @@ interface Props {
[key: string]: any;
};
condition;
values;
variables: VariablesContextType;
localVariables: VariableOption[];
}
@ -36,7 +35,6 @@ export const collectFieldStateOfLinkageRules = ({
value,
field,
condition,
values,
variables,
localVariables,
}: Props) => {

View File

@ -1,4 +1,4 @@
import { untracked } from '@formily/reactive';
import { raw, untracked } from '@formily/reactive';
import { getValuesByPath } from '@nocobase/utils/client';
import _ from 'lodash';
import React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react';
@ -124,7 +124,13 @@ const VariablesProvider = ({ children }) => {
data = await waitForData;
clearRequested(url);
}
current[key] = data.data.data;
// fix https://nocobase.height.app/T-3144使用 `raw` 方法是为了避免触发 autorun以修复 T-3144 的错误
if (!raw(current)[key]) {
// 把接口返回的数据保存起来,避免重复请求
raw(current)[key] = data.data.data;
}
current = getValuesByPath(current, key);
} else {
current = getValuesByPath(current, key);