From ca29515bcd8b666fd89a3ad29f21ed005bef318c Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Thu, 18 Apr 2024 16:52:34 +0800 Subject: [PATCH] perf(LinkageRules): solve lagging problems (#4090) --- .../antd/form-dialog/index.tsx | 6 ++-- .../schema-settings/LinkageRules/index.tsx | 35 +++++++------------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-dialog/index.tsx b/packages/core/client/src/schema-component/antd/form-dialog/index.tsx index 917e6e08fa..1400777072 100644 --- a/packages/core/client/src/schema-component/antd/form-dialog/index.tsx +++ b/packages/core/client/src/schema-component/antd/form-dialog/index.tsx @@ -1,6 +1,6 @@ import { createForm, Form, IFormProps } from '@formily/core'; import { FormProvider, Observer, observer, ReactFC } from '@formily/react'; -import { toJS } from '@formily/reactive'; +import { untracked } from '@formily/reactive'; import { applyMiddleware, IMiddleware, isBool, isFn, isNum, isStr } from '@formily/shared'; import { Modal, ModalProps, ThemeConfig } from 'antd'; import React, { Fragment, useLayoutEffect, useRef, useState } from 'react'; @@ -161,7 +161,9 @@ export function FormDialog(title: any, id: any, renderer?: any, theme?: any): IF env.form ?.submit(async () => { await applyMiddleware(env.form, env.confirmMiddlewares); - resolve(toJS(env.form?.values)); + untracked(() => { + resolve({ ...env.form?.values }); + }); formDialog.close(); }) .catch(() => {}); diff --git a/packages/core/client/src/schema-settings/LinkageRules/index.tsx b/packages/core/client/src/schema-settings/LinkageRules/index.tsx index fce4ed2874..8147f4c7d8 100644 --- a/packages/core/client/src/schema-settings/LinkageRules/index.tsx +++ b/packages/core/client/src/schema-settings/LinkageRules/index.tsx @@ -1,7 +1,7 @@ import { css } from '@emotion/css'; -import { Form } from '@formily/core'; import { observer, useFieldSchema } from '@formily/react'; import React, { useMemo } from 'react'; +import { withDynamicSchemaProps } from '../../application/hoc/withDynamicSchemaProps'; import { FormBlockContext } from '../../block-provider'; import { useCollectionManager_deprecated } from '../../collection-manager'; import { useCollectionParentRecordData } from '../../data-source/collection-record/CollectionRecordProvider'; @@ -9,26 +9,10 @@ import { RecordProvider } from '../../record-provider'; import { SchemaComponent, useProps } from '../../schema-component'; import { DynamicComponentProps } from '../../schema-component/antd/filter/DynamicComponent'; import { FilterContext } from '../../schema-component/antd/filter/context'; -import { VariableOption, VariablesContextType } from '../../variables/types'; import { VariableInput, getShouldChange } from '../VariableInput/VariableInput'; import { LinkageRuleActionGroup } from './LinkageRuleActionGroup'; import { EnableLinkage } from './components/EnableLinkage'; import { ArrayCollapse } from './components/LinkageHeader'; -import { withDynamicSchemaProps } from '../../application/hoc/withDynamicSchemaProps'; - -interface usePropsReturn { - options: any; - defaultValues: any[]; - collectionName: string; - form: Form; - variables: VariablesContextType; - localVariables: VariableOption | VariableOption[]; - record: Record; - /** - * create 表示创建表单,update 表示更新表单 - */ - formBlockType: 'create' | 'update'; -} interface Props { dynamicComponent: any; @@ -124,10 +108,7 @@ export const FormLinkageRules = withDynamicSchemaProps( }, action: { type: 'void', - 'x-component': LinkageRuleActionGroup, - 'x-component-props': { - ...props, - }, + 'x-component': (_props) => , }, }, }, @@ -167,7 +148,17 @@ export const FormLinkageRules = withDynamicSchemaProps( }, }, }), - [collectionName, defaultValues, form, localVariables, options, props, record, variables], + [ + collectionName, + defaultValues, + form, + getAllCollectionsInheritChain, + localVariables, + options, + props, + record, + variables, + ], ); const value = useMemo( () => ({ field: options, fieldSchema, dynamicComponent, options: options || [] }),