Visitar URL original
fix(@rjsf/core): prevent extraErrors duplication on array field mutation (#5041) by JosephDoUrden · Pull Request #5044 · rjsf-team/react-jsonschema-form · GitHub
Skip to content

fix(@rjsf/core): prevent extraErrors duplication on array field mutation (#5041) - #5044

Merged
heath-freenome merged 3 commits into
rjsf-team:mainfrom
JosephDoUrden:fix/issue-5041-extra-errors-duplicated-on-array-mutation
Apr 30, 2026
Merged

heath-freenome merged 3 commits into
rjsf-team:mainfrom
JosephDoUrden:fix/issue-5041-extra-errors-duplicated-on-array-mutation

Conversation

@JosephDoUrden

Copy link
Copy Markdown
Contributor

Reasons for making this change

processPendingChange() used this.state.errorSchema (which already contains merged extraErrors) as the base when re-merging extraErrors in the non-live-validate branch. Because validationDataMerge concatenates __errors arrays, each array mutation triggered an extra merge cycle that appended duplicate copies of any sibling field's extraErrors.

The fix uses schemaValidationErrorSchema (the un-merged AJV-only base) instead, which is consistent with how getDerivedStateFromProps and getStateFromProps handle the same merge pattern.

Fixes #5041

Changes

  • In Form.processPendingChange(), replaced originalErrorSchema with schemaValidationErrorSchema as the base passed to mergeErrors() in the else if (!noValidate && newErrorSchema) branch
  • Added regression test: sibling field extraErrors must not accumulate after array item is added

Checklist

  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated the changelog with a description of the PR

processPendingChange() used originalErrorSchema (which already contains
merged extraErrors) as the base for re-merging extraErrors in the
non-live-validate branch. Because validationDataMerge concatenates
__errors arrays, each array mutation triggered an extra merge cycle that
appended duplicate copies of any sibling field's extraErrors.

The fix uses schemaValidationErrorSchema (the un-merged AJV-only base)
instead, consistent with how getDerivedStateFromProps and getStateFromProps
handle the same merge pattern.

Fixes rjsf-team#5041
Comment thread packages/core/src/components/Form.tsx Resolved
@heath-freenome

Copy link
Copy Markdown
Member

@JosephDoUrden Looks like your tests are failing

JosephDoUrden and others added 2 commits April 29, 2026 22:57
Addresses review feedback. The previous patch swapped state.errorSchema
for schemaValidationErrorSchema as the merge base, but that dropped the
caller-supplied newErrorSchema mutations applied earlier in the same
function, breaking ArrayField swap/remove/insert/copy tests.

Introduce a local mergeBaseErrorSchema starting from the AJV-only
schemaValidationErrorSchema and apply the path-level newErrorSchema
onto a clone (or replace at root) before mergeErrors. extraErrors at
sibling paths are no longer concatenated twice, and the path the user
just edited still shows the error they passed in.
@heath-freenome
heath-freenome merged commit 7148fc4 into rjsf-team:main Apr 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extra errors duplicated when a sibling array field is mutated

2 participants