fix(TableForm): validateWholeFields() repeated calls and error overwrite#1234
Open
MrWindlike wants to merge 2 commits intov490-devfrom
Open
fix(TableForm): validateWholeFields() repeated calls and error overwrite#1234MrWindlike wants to merge 2 commits intov490-devfrom
MrWindlike wants to merge 2 commits intov490-devfrom
Conversation
…alidation Replace boolean validateAll state with a counter (validateAllCount) so that each call to validateWholeFields() increments the value and always triggers a React re-render. Previously, calling setValidateAll(true) when already true was a no-op, causing the validation useEffect to skip and isValid() to incorrectly return true due to vacuous truth on an empty formValidMapRef. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…r results When validateWholeFields() triggers setIsTouched(true), the isTouched change causes the error prop sync useEffect to fire. Since the error prop is typically undefined, it was overwriting the validateResult just set by triggerValidate(). Use a prevErrorRef to track whether the error prop actually changed, and only clear validateResult when the error prop transitions from truthy to falsy, not when isTouched changes with a falsy error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
能不能补充下 bug 在业务上的现象? |
chenenpei
reviewed
Feb 6, 2026
| msg: error, | ||
| isError: true, | ||
| }); | ||
| } else if (errorChanged) { |
Contributor
There was a problem hiding this comment.
我没看懂这个改动的逻辑。
如果 isTouched 为 true,又有 erro 就设置 error。如果 error 是 undefined 还要比较一次,这是为什么呢?为什么不多做这一次比较会有问题呢?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validateAll是 boolean 状态,setValidateAll(true)在已为true时是 React no-op,不触发 re-render,formValidMapRef被清空后无法重新填充,isValid()因 vacuous truth 返回truetriggerValidate()设置的validateResult会被 error prop sync effect 覆盖清空,因为setIsTouched(true)导致isTouched变化触发该 effect,而errorprop 为undefined时直接将validateResult置为undefinedFix
validateAll: boolean改为validateAllCount: number(递增计数器),确保每次validateWholeFields()都触发 re-renderprevErrorRef追踪errorprop 前值,仅在error确实从有值变为空时才清除validateResult,避免isTouched变化时误清校验结果Changed files
types.tsvalidateAll: boolean→validateAllCount: numberindex.tsxuseState(false)→useState(0),setValidateAll(true)→setValidateAllCount(c => c + 1)TableFormBodyCell.tsxvalidateAllCount;添加prevErrorRef防止 error sync effect 覆盖 validator 结果TableFormBodyRows.tsxTest plan
validateWholeFields()一次,无效数据 →isValid()返回falsevalidateWholeFields()→isValid()仍为falsevalidateWholeFields()→isValid()返回trueerrorsprop 外部设置/清除仍然正常工作🤖 Generated with Claude Code