Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form): unexpected validate error before unRegister #1752

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SyMind
Copy link
Contributor

@SyMind SyMind commented Aug 5, 2023

中文模板 / Chinese Template

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Test Case
  • TypeScript definition update
  • Document improve
  • CI/CD improve
  • Branch sync
  • Other, please describe:

PR description

Fixes #

Changelog

🇨🇳 Chinese

  • Fix: 修复动态表单,动态删除表单项后,再次增加该表单项目时,存在校验错误的情况。

复现步骤请见单元测试。


🇺🇸 English

  • Fix: fix ...

Checklist

  • Test or no need
  • Document or no need
  • Changelog or no need

Other

  • Skip Changelog

Additional information

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 5, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0d04313:

Sandbox Source
pr-story Configuration
Semi Design: Simple Story Configuration

@SyMind SyMind changed the title fix: validate before unRegister fix(form): unexpected validate error before unRegister Aug 5, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2023

Codecov Report

Patch coverage: 87.50% and project coverage change: +0.03% 🎉

Comparison is base (015ad15) 88.01% compared to head (8d33fad) 88.05%.
Report is 3 commits behind head on main.

❗ Current head 8d33fad differs from pull request most recent head b8dbd9d. Consider uploading reports for the commit b8dbd9d to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1752      +/-   ##
==========================================
+ Coverage   88.01%   88.05%   +0.03%     
==========================================
  Files         433      433              
  Lines       25246    25253       +7     
  Branches     6360     6362       +2     
==========================================
+ Hits        22221    22236      +15     
+ Misses       3025     3017       -8     
Files Changed Coverage Δ
packages/semi-ui/image/preview.tsx 90.90% <ø> (ø)
packages/semi-ui/image/previewInner.tsx 98.77% <ø> (ø)
packages/semi-ui/form/hoc/withField.tsx 87.81% <85.71%> (+1.23%) ⬆️
packages/semi-ui/_portal/index.tsx 96.00% <88.88%> (ø)

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

text: 'foo',
});
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 Demo 我有点疑问哈,跟 description里描述的场景似乎不太一样。

这个test case的逻辑,我理解的是

  1. 初始 Field Input 有值 'semi'
  2. 然后将值删除成空字符串,此时触发了校验
  3. 然后再使用 formApi.setValue 设成另外一个值
  4. 希望 error 不存在?
() => {
    const formRef = useRef();
    const change = () => {
        formRef.current.formApi.setValue('text', 'foo');
    };
    return (
        <Form
            initValues={{
                text: 'semi',
            }}
            ref={formRef}
        >
            {({ formState }) => (
                <>
                    {!!formState.values.text && (
                        <Form.Input
                            field="text"
                            rules={[
                                { required: true },
                            ]}
                        />
                    )}
                    <Button onClick={() => change()}>change</Button>
                </>
            )}
        </Form>
    )
}   

20230814165234_rec_

@@ -196,6 +202,9 @@ function withField<
if (validatePromise.current !== rootPromise) {
return;
}
if (unmounted.current) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但这里的改动,我看着像是为了解决 组件触发校验后(例如 async 的validate),如果最终结果return时,field已经被卸载了,就不再消费 error。

跟【动态删除表单项后,再次增加该表单项目时,存在校验错误】严格意义上也不是一码事?

@pointhalo pointhalo added the need more info Can't reproduce the problem, need to provide more context label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Can't reproduce the problem, need to provide more context
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants