Skip to content

Commit

Permalink
fix(form): alway use shouldUpdate for json
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jun 17, 2023
1 parent ad537a5 commit 7933961
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@umijs/utils": "^4.0.70",
"animated-scroll-to": "^2.3.0",
"antd": "^5.6.1",
"antd-style": "beta",
"antd-style": "^3.3.0",
"babel-loader": "^9.1.2",
"babel-types": "^6.26.0",
"chalk": "^4.1.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/form/src/components/SchemaForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, {
useRef,
useState,
} from 'react';
import { stringify } from 'use-json-comparison';
import type { ProFormInstance } from '../../BaseForm';
import type { ProFormProps } from '../../layouts';
import { DrawerForm } from '../../layouts/DrawerForm';
Expand Down Expand Up @@ -57,7 +58,7 @@ function BetaSchemaForm<T, ValueType = 'text'>(
layoutType = 'Form',
type = 'form',
action,
shouldUpdate = true,
shouldUpdate = (pre, next) => stringify(pre) !== stringify(next),
formRef: propsFormRef,
...restProps
} = props;
Expand Down
1 change: 1 addition & 0 deletions packages/form/src/layouts/QueryFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ const QueryFilterContent: React.FC<{
<Form.Item
label=" "
colon={false}
shouldUpdate={false}
className={`${baseClassName}-actions ${hashId}`.trim()}
>
<Actions
Expand Down
20 changes: 19 additions & 1 deletion packages/utils/src/components/InlineErrorFormItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { FormItemProps, PopoverProps } from 'antd';
import { ConfigProvider, Form, Popover } from 'antd';
import type { NamePath } from 'rc-field-form/lib/interface';
import get from 'rc-util/lib/utils/get';
import React, { useContext, useEffect, useState } from 'react';
import { openVisibleCompatible } from '../../compareVersions/openVisibleCompatible';
import { useStyle } from './style';
Expand Down Expand Up @@ -94,7 +95,10 @@ const InternalFormItemFunction: React.FC<InternalProps & FormItemProps> = ({
hasFeedback={false}
shouldUpdate={(prev, next) => {
try {
return JSON.stringify(prev) !== JSON.stringify(next);
return (
JSON.stringify(get(prev, [name].flat(1))) !==
JSON.stringify(get(next, [name].flat(1)))
);
} catch (error) {
return true;
}
Expand Down Expand Up @@ -148,6 +152,20 @@ export const InlineErrorFormItem = (props: InlineErrorFormItemProps) => {
return (
<Form.Item
rules={rules}
shouldUpdate={
name
? (prev, next) => {
try {
return (
JSON.stringify(get(prev, [name].flat(1))) !==
JSON.stringify(get(next, [name].flat(1)))
);
} catch (error) {
return true;
}
}
: undefined
}
{...rest}
style={{ ...FIX_INLINE_STYLE, ...rest.style }}
name={name}
Expand Down
26 changes: 2 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7933961

Please sign in to comment.