Skip to content

fix: list an extraErrors message once when it matches a validator error - #5443

Merged
heath-freenome merged 16 commits into
rjsf-team:v7from
drakeo338:claude/5442-fix
Oct 12, 2026
Merged

heath-freenome merged 16 commits into
rjsf-team:v7from
drakeo338:claude/5442-fix

Conversation

@drakeo338

@drakeo338 drakeo338 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Reasons for making this change

Fixes #5442.

On v7, #5470 already lists a widget-raised error once when the validator reports the same message at the same path. What was still duplicated is an extraErrors message equal to a validator error: Form merged extraErrors without preventDuplicates, so it showed twice on the field, in the ErrorList, and in the errors passed to onError and onChange.

This PR:

  • merges extraErrors with preventDuplicates in formState's mergeErrors();
  • makes validationDataMerge() with preventDuplicates leave out of the appended errors exactly what mergeObjects() leaves out of the merged errorSchema (a message the existing errorSchema already holds under the same keys), so the list and the fields cannot disagree. mergeErrors() now relies on that for both merges instead of keeping its own filter;
  • adds propertyToPath() to @rjsf/utils and uses it in toErrorSchema(), formState and formModel.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run pnpm exec nx run-many --target=build --exclude=@rjsf/docs && pnpm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Tested with the @rjsf/utils, @rjsf/core and three validator test suites, pnpm run cs-check and pnpm run lint. The snapshot command was not run because the change touches no snapshots.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Size limit report

Sizes are minified + brotli, measured by size-limit at a918060.

A package listed twice is measured both as installed and, on the second row, as its own code with its dependencies excluded. Peer dependencies are always excluded.

Check Base PR Δ
@rjsf/antd 7.16 kB 7.16 kB =
@rjsf/antd (without dependencies) 6.75 kB 6.75 kB =
@rjsf/chakra-ui 18.79 kB 18.79 kB =
@rjsf/chakra-ui (without dependencies) 10.71 kB 10.71 kB =
@rjsf/core 30.74 kB 30.66 kB -0.07 kB
@rjsf/core/markdown 25.53 kB 25.53 kB =
@rjsf/core/testing 60.81 kB 60.86 kB +0.05 kB
@rjsf/core: Form 30.52 kB 30.39 kB -0.13 kB
@rjsf/daisyui 53.85 kB 53.85 kB =
@rjsf/daisyui (without dependencies) 11.00 kB 11.00 kB =
@rjsf/fluentui-rc 5.75 kB 5.75 kB =
@rjsf/mantine 14.34 kB 14.34 kB =
@rjsf/mantine (without dependencies) 9.98 kB 9.98 kB =
@rjsf/mui 6.56 kB 6.56 kB =
@rjsf/react-bootstrap 7.76 kB 7.76 kB =
@rjsf/react-bootstrap (without dependencies) 5.31 kB 5.31 kB =
@rjsf/shadcn 43.49 kB 43.49 kB =
@rjsf/shadcn (without dependencies) 9.11 kB 9.11 kB =
@rjsf/utils 29.53 kB 29.60 kB +0.07 kB
@rjsf/utils (without dependencies) 23.97 kB 24.01 kB +0.04 kB
@rjsf/utils: getUiOptions 0.65 kB 0.65 kB =
@rjsf/validator-ajv8 38.14 kB 38.14 kB =
@rjsf/validator-ajv8 (without dependencies) 2.66 kB 2.66 kB =
@rjsf/validator-ata 86.24 kB 86.24 kB =
@rjsf/validator-ata (without dependencies) 2.41 kB 2.41 kB =
@rjsf/validator-cfworker 7.22 kB 7.22 kB =
@rjsf/validator-cfworker (without dependencies) 2.30 kB 2.30 kB =

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking up #5442! The direction looks right, but the duplicate check compares property strings instead of paths, so the double listing still happens for several common spellings (details inline).

Two more points that fall outside the diff:

  1. extraErrors still duplicates (packages/core/src/components/Form.tsx:533). mergeErrors merges extraErrors without preventDuplicates. So an extraErrors message identical to a validator error is still listed twice in the ErrorList and on the field. For example, extraErrors={{ addr: { street: { __errors: ['must NOT have fewer than 3 characters'] } } }} with a 1-character street. The fix currently covers only widget-raised (customErrors) errors. That may be intentional, but it's worth deciding explicitly.
  2. Existing bug in validationDataMerge(), not from this PR: when oldErrorSchema is empty but oldErrors isn't, the merge branch is skipped and oldErrors is thrown away. This happens when a transformErrors clears message, so toErrorSchema() leaves those errors out. The comment at Form.tsx:601 describes the same situation. A widget-raised error then makes mergeErrors return only toErrorList(customErrors), dropping the validator's errors from the ErrorList and from onError. It's fine as a follow-up, but since this PR already touches the function it may be easy to fix here.

Comment thread CHANGELOG.md Resolved
@drakeo338

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. The path-keyed dedupe (toPath, so foo/.foo, ''/., .arr[0]/.arr.0 match) and the CHANGELOG-v7.md entry are in. Point 1: mergeErrors now passes preventDuplicates for extraErrors too, with a test. Point 2: validationDataMerge now keeps oldErrors when oldErrorSchema is empty, with a test. I also merged v7 and changed one Form.behaviors expectation that counted the duplicated extraErrors message twice.

@heath-freenome

Copy link
Copy Markdown
Member

@drakeo338 Can you rebase onto the latest v7 and resolve conflicts

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, every point from the last round is addressed, and the path-keyed dedupe handles foo/.foo, ''/. and .arr[0]/.arr.0 as intended. The inline comments are mostly side effects of keeping the old errors, plus a few nits.

Two things that aren't on lines in the diff:

  • Rebase: the branch still conflicts with v7 (CHANGELOG-v7.md and packages/core/test/Form.errors.test.tsx), as mentioned above.
  • API docs: packages/docs/docs/api-reference/utility-functions.md:2259 still says preventDuplicates only passes the flag to mergeObjects(). It should also say that additional errors already in the list (same path and message) are skipped, and that existing errors are kept when their errorSchema is empty, matching the JSDoc you updated.

Not for this PR: keys escaped as ~0/~1 still aren't deduplicated, but the cause is upstream. The validators build property with instancePath.replace(/\//g, '.'), so a key a/b is reported as .a~1b, and that error never reaches the a/b field at all. That's a separate validator issue.

Comment thread CHANGELOG-v7.md Resolved
Comment thread packages/core/test/Form.errors.test.tsx Resolved
@drakeo338

Copy link
Copy Markdown
Contributor Author

Merged the latest v7 into the branch with the conflicts resolved, and updated the validationDataMerge() entry in utility-functions.md to say what preventDuplicates skips and that existing errors are kept when their errorSchema is empty, in 6e80396.

@heath-freenome heath-freenome left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @drakeo338. All six points from the last round are addressed, and the code looks right to me. What's left is changelog wording and one small nit, in the inline comments. The branch is one commit behind v7 again (#5429), but it merges cleanly.

One thing for a separate issue, not this PR: a widget-raised error that matches the validator's error never clears after submit. With this PR's StreetWidget (minLength 3), type a, submit, then type bc. Both the field and the ErrorList still show "must NOT have fewer than 3 characters" for the valid abc. The empty raise only unsets the validator's copy, and the copy in customErrors stays. v7 behaves the same, so this PR didn't cause it, but it's the same flow as #5442 and nothing tests that the error clears. Could you open an issue for it, with these steps?

Comment thread CHANGELOG-v7.md Resolved
Comment thread CHANGELOG-v7.md Resolved
Comment thread CHANGELOG-v7.md Resolved
Comment thread packages/utils/src/toErrorSchema.ts Resolved
@heath-freenome

Copy link
Copy Markdown
Member

@drakeo338 This could use a rebase w/ conflict merge

drakeo338 and others added 6 commits October 11, 2026 11:58
… error

validationDataMerge() with preventDuplicates dropped the duplicate message
from the ErrorSchema but still concatenated the flat errors list, so the top
ErrorList showed the message twice after submit.
The errors filter compared raw property strings, so spellings of one
location that differ (foo vs .foo, '' vs ., .arr[0] vs .arr.0) kept the
double listing the errorSchema merge already removes. Key both sides by the
toPath() split that toErrorSchema() uses, with a Set built once from the
existing errors. Move the changelog entry to CHANGELOG-v7.md.
…mpty errorSchema

mergeErrors() now merges extraErrors with preventDuplicates, so an extraErrors
message equal to a validator error at the same path is listed once in the
ErrorList and on the field. validationDataMerge() no longer drops the existing
errors when their errorSchema is empty (a transformErrors that clears message).
…ata fields

Export propertyToPath() from @rjsf/utils for the `property ? toPath(property) : []`
split that validationDataMerge(), toErrorSchema() and Form each spelled out.
validationDataMerge() defaults a missing errors or errorSchema instead of
throwing, and builds its duplicate Set only when there are errors to add.

Note in CHANGELOG-v7.md that keeping the existing errors changes what the
validators' validateFormData() returns and Form passes to onError. Spell out the
listed errors per case in Form.behaviors.test.tsx, run the extraErrors dedupe
test with extraErrorsAreWarnings unset and true, and update the test that
recorded the duplicate listing as current behaviour.
Add a validateFormData() test to each of ajv8, ata and cfworker where a
transformErrors clears every message and customValidate adds an error: the
cleared errors now come back with the custom one. Note this under the three
validator headings in CHANGELOG-v7.md.

validationDataMerge() merges unconditionally now that errors and errorSchema
default to empty, and the API docs say what preventDuplicates skips and that
existing errors are kept when their errorSchema is empty.
@drakeo338

Copy link
Copy Markdown
Contributor Author

Rebased onto v7 and resolved the conflicts in the changelog, validationDataMerge and the Form tests, and the extraErrors dedupe now sits in formState's mergeErrors; tests, lint and format pass.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @drakeo338, the rebase is clean and most of the last round is in. I've resolved the threads that are done. Still open: the propertyToPath() changelog bullet, the toErrorSchema.ts comment, using propertyToPath() in core, and point 2 of the core changelog thread (the dedupe reaching onError/onChange).

The widget-raised case is already fixed on v7. #5470 added a filter to formState.ts's mergeErrors() that lists a raised error once when the validator reports the same message at the same path. Run against v7's source, this PR's widget-raised tests already pass, and only the extraErrors tests fail. So what this PR actually changes is the extraErrors dedupe plus the path-keyed list filter in validationDataMerge(). Could you retitle the PR to match, and reword the changelog (see inline)?

The inline comments cover what the rebase onto #5469 and #5470 left behind: overlaps with what v7 now does, and two edge cases in the path matching.

Comment thread CHANGELOG-v7.md Resolved
drakeo338 and others added 4 commits October 11, 2026 19:16
…orSchema comment

formState's private errorPath() and focusOnError() in formModel spelled out
the split propertyToPath() makes, so they could drift from toErrorSchema() and
validationDataMerge(). The comment above toErrorSchema's propertyToPath() call
still named toPath and repeated the helper's JSDoc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the rebase onto rjsf-team#5469 the validators' src is untouched, and rjsf-team#5469's
'validateFormData() with a transformErrors that clears every message' blocks
already cover the cleared errors coming back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With preventDuplicates, the appended errors are now toErrorList() of the
additional ErrorSchema without the messages the existing errorSchema already
holds under the same keys, which are exactly the ones mergeObjects() leaves
out. The list and the merged errorSchema can no longer disagree: a property
named 'a.b' next to a nested a -> b, and a root error next to an
invalid-schema error held under $schema, are both listed where the merge
shows them. Any spelling of the existing error's property still matches,
since toErrorSchema() has already split it into keys.

The missing-field defaults are gone, so a validationData without errors
throws as rjsf-team#5469's changelog says. Drop the test that repeated v7's 'Keeps the
existing errors when their errorSchema is empty', reword the utils changelog
bullet to what this changes, and add one for propertyToPath().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
validationDataMerge(..., true) already leaves out of the list what it leaves
out of the errorSchema, so rjsf-team#5470's keyOf/listedKeys filter over the raised
errors repeated it with a second definition of the same error. Both merges
now go through validationDataMerge() alone.

The core changelog bullet says the extraErrors dedupe reaches the errors
passed to onError and onChange too, and the tests check both. The ErrorList
comment no longer compares against the old behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@drakeo338 drakeo338 changed the title fix: list a widget-raised error once when it matches a validator error fix: list an extraErrors message once when it matches a validator error Oct 11, 2026

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @drakeo338, everything from the last round is in, and I've resolved all the open threads. Matching on the errorSchema keys is a nice way to keep the list and the fields in step.

What's left is small: one cleanup in validationDataMerge(), a test that repeats an existing one, a regression test worth adding, and one more edge case (fine to accept).

Comment thread packages/core/test/Form.errors.test.tsx Resolved
Comment thread packages/core/test/Form.errors.test.tsx Resolved

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working through all the rounds of feedback. Approving.

validationDataMerge()'s dedupe takes the package to 24.01 kB, just over the 24 kB budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@heath-freenome
heath-freenome merged commit e6fdd57 into rjsf-team:v7 Oct 12, 2026
7 checks passed
@heath-freenome heath-freenome mentioned this pull request Nov 13, 2026
Merged
8 tasks
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.

2 participants