-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix 4796 by simplifying Form onChange error processing #4799
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
Merged
Conversation
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
Fixes rjsf-team#4796 by simplifying `Form.onChange` error processing and removing old code in `LayoutGridField` - In `@rjsf/utils` - Updated `validationDataMerge()` to add an additional, optional parameter `preventDuplicates = false`, that causes the `mergeObjects()` call to receive `preventDuplicates` instead of `true` - In `@rjsf/core`, updated `Form` as follows to fix [rjsf-team#4796](rjsf-team#4796) - Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()` - Added new, optional `customErrors?: ErrorSchemaBuilder<T>` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables - Reworked the `newErrorSchema` handling in `processPendingChange()` to simplify the handling since `newErrorSchema` is now path-specific, adding `newErrorSchema` to `customErrors` when they don't match an existing validator-based validation - This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage - Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods - Also, updated `LayoutGridField` to simplify `onFieldChange()` to just return the given `errorSchema` now that it is path-specific, fixing [rjsf-team#4796](rjsf-team#4796) - Also, updated `NullField` to pass `fieldPathId.path` for the `onChange()` instead of `[name]` - Updated the tests for `StringField`, `ArrayField` and `ObjectField` to verify all of the new error processing logic in `onChange()` - Updated `utility-functions.md` to update the `validationDataMerge()` function's new parameter - Updated `custom-widgets-fields.md` to change the documentation around passing errors via `onChange()` to reflect the new reality - Updated the `CHANGELOG.md` accordingly # Conflicts: # CHANGELOG.md
06909bb
to
8d3de6d
Compare
heath-freenome
commented
Oct 8, 2025
set(newErrorSchema, dottedPath, errSchema); | ||
} | ||
onChange(value, path, newErrorSchema, id); | ||
const { onChange } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this change fixed the bulk of the performance issue.
heath-freenome
commented
Oct 8, 2025
useEffect(() => { | ||
if (formData === undefined) { | ||
onChange(null as unknown as T, [name]); | ||
onChange(null as unknown as T, fieldPathId.path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, missed one place from my previous PR
nickgros
approved these changes
Oct 8, 2025
Co-authored-by: Nick Grosenbacher <[email protected]>
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.
Reasons for making this change
Fixes #4796 by simplifying
Form.onChange
error processing and removing old code inLayoutGridField
@rjsf/utils
validationDataMerge()
to add an additional, optional parameterpreventDuplicates = false
, that causes themergeObjects()
call to receivepreventDuplicates
instead oftrue
@rjsf/core
, updatedForm
as follows to fix #4796liveValidate()
andmergeErrors()
functions out ofgetStateFromProp()
andprocessPendingChange()
customErrors?: ErrorSchemaBuilder<T>
to theFormState
, updating theIChangeEvent
interface to remove all of the private variablesnewErrorSchema
handling inprocessPendingChange()
to simplify the handling sincenewErrorSchema
is now path-specific, addingnewErrorSchema
tocustomErrors
when they don't match an existing validator-based validationgetPreviousCustomValidateErrors()
andfilterErrorsBasedOnSchema()
methodsLayoutGridField
to simplifyonFieldChange()
to just return the givenerrorSchema
now that it is path-specific, fixing #4796NullField
to passfieldPathId.path
for theonChange()
instead of[name]
StringField
,ArrayField
andObjectField
to verify all of the new error processing logic inonChange()
utility-functions.md
to update thevalidationDataMerge()
function's new parametercustom-widgets-fields.md
to change the documentation around passing errors viaonChange()
to reflect the new realityv6.x upgrade guide.md
to document the changes mentioned aboveCHANGELOG.md
accordinglyChecklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.