mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix(assigned-field): prevent deep cloning of React elements in scope (#7086)
* fix(assigned-field): prevent deep cloning of React elements in scope * fix: simplify variable value assignment in action props
This commit is contained in:
parent
cca6b0faaf
commit
544f561b26
@ -197,9 +197,7 @@ export function useCollectValuesToSubmit() {
|
|||||||
|
|
||||||
if (isVariable(value)) {
|
if (isVariable(value)) {
|
||||||
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
||||||
if (parsedValue !== null && parsedValue !== undefined) {
|
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
||||||
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
|
||||||
}
|
|
||||||
} else if (value !== '') {
|
} else if (value !== '') {
|
||||||
assignedValues[key] = value;
|
assignedValues[key] = value;
|
||||||
}
|
}
|
||||||
@ -385,9 +383,7 @@ export const useAssociationCreateActionProps = () => {
|
|||||||
|
|
||||||
if (isVariable(value)) {
|
if (isVariable(value)) {
|
||||||
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
||||||
if (parsedValue) {
|
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
||||||
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
|
||||||
}
|
|
||||||
} else if (value !== '') {
|
} else if (value !== '') {
|
||||||
assignedValues[key] = value;
|
assignedValues[key] = value;
|
||||||
}
|
}
|
||||||
@ -658,9 +654,7 @@ export const useCustomizeUpdateActionProps = () => {
|
|||||||
|
|
||||||
if (isVariable(value)) {
|
if (isVariable(value)) {
|
||||||
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
||||||
if (parsedValue) {
|
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
||||||
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
|
||||||
}
|
|
||||||
} else if (value !== '') {
|
} else if (value !== '') {
|
||||||
assignedValues[key] = value;
|
assignedValues[key] = value;
|
||||||
}
|
}
|
||||||
@ -771,9 +765,7 @@ export const useCustomizeBulkUpdateActionProps = () => {
|
|||||||
|
|
||||||
if (isVariable(value)) {
|
if (isVariable(value)) {
|
||||||
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
||||||
if (parsedValue) {
|
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
||||||
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
|
||||||
}
|
|
||||||
} else if (value !== '') {
|
} else if (value !== '') {
|
||||||
assignedValues[key] = value;
|
assignedValues[key] = value;
|
||||||
}
|
}
|
||||||
@ -999,9 +991,7 @@ export const useUpdateActionProps = () => {
|
|||||||
|
|
||||||
if (isVariable(value)) {
|
if (isVariable(value)) {
|
||||||
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
const { value: parsedValue } = (await variables?.parseVariable(value, localVariables)) || {};
|
||||||
if (parsedValue) {
|
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
||||||
assignedValues[key] = transformVariableValue(parsedValue, { targetCollectionField: collectionField });
|
|
||||||
}
|
|
||||||
} else if (value !== '') {
|
} else if (value !== '') {
|
||||||
assignedValues[key] = value;
|
assignedValues[key] = value;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,9 @@
|
|||||||
import { Field } from '@formily/core';
|
import { Field } from '@formily/core';
|
||||||
import { useField, useFieldSchema } from '@formily/react';
|
import { useField, useFieldSchema } from '@formily/react';
|
||||||
import { merge } from '@formily/shared';
|
import { merge } from '@formily/shared';
|
||||||
import _ from 'lodash';
|
import _, { cloneDeepWith } from 'lodash';
|
||||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
import React, { isValidElement, useCallback, useEffect, useMemo } from 'react';
|
||||||
|
import { useBlockContext } from '../../../block-provider';
|
||||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||||
import {
|
import {
|
||||||
useCollectionField_deprecated,
|
useCollectionField_deprecated,
|
||||||
@ -20,14 +21,13 @@ import {
|
|||||||
useCollection_deprecated,
|
useCollection_deprecated,
|
||||||
} from '../../../collection-manager';
|
} from '../../../collection-manager';
|
||||||
import { CollectionFieldProvider } from '../../../data-source';
|
import { CollectionFieldProvider } from '../../../data-source';
|
||||||
|
import { FlagProvider } from '../../../flag-provider';
|
||||||
import { useRecord } from '../../../record-provider';
|
import { useRecord } from '../../../record-provider';
|
||||||
import { useCompile, useComponent } from '../../../schema-component';
|
import { useCompile, useComponent } from '../../../schema-component';
|
||||||
import { VariableInput, getShouldChange } from '../../../schema-settings/VariableInput/VariableInput';
|
import { VariableInput, getShouldChange } from '../../../schema-settings/VariableInput/VariableInput';
|
||||||
import { Option } from '../../../schema-settings/VariableInput/type';
|
import { Option } from '../../../schema-settings/VariableInput/type';
|
||||||
import { formatVariableScop } from '../../../schema-settings/VariableInput/utils/formatVariableScop';
|
import { formatVariableScop } from '../../../schema-settings/VariableInput/utils/formatVariableScop';
|
||||||
import { useLocalVariables, useVariables } from '../../../variables';
|
import { useLocalVariables, useVariables } from '../../../variables';
|
||||||
import { useBlockContext } from '../../../block-provider';
|
|
||||||
import { FlagProvider } from '../../../flag-provider';
|
|
||||||
interface AssignedFieldProps {
|
interface AssignedFieldProps {
|
||||||
value: any;
|
value: any;
|
||||||
onChange: (value: any) => void;
|
onChange: (value: any) => void;
|
||||||
@ -126,7 +126,14 @@ export const AssignedFieldInner = (props: AssignedFieldProps) => {
|
|||||||
currentForm.children = formatVariableScop(currentFormFields);
|
currentForm.children = formatVariableScop(currentFormFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope;
|
return cloneDeepWith(scope, (value) => {
|
||||||
|
// 不对 `ReactElement` 进行深拷贝,因为会报错
|
||||||
|
if (isValidElement(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
// 对于其他类型的对象,继续正常的深拷贝
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[currentFormFields, name],
|
[currentFormFields, name],
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user