Skip to content

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Oct 8, 2025

Reasons for making this change

Fixes #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 #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 #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 v6.x upgrade guide.md to document the changes mentioned above
  • Updated the CHANGELOG.md accordingly

Checklist

  • I'm updating documentation
  • 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 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

@heath-freenome heath-freenome self-assigned this Oct 8, 2025
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
set(newErrorSchema, dottedPath, errSchema);
}
onChange(value, path, newErrorSchema, id);
const { onChange } = this.props;
Copy link
Member Author

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.

useEffect(() => {
if (formData === undefined) {
onChange(null as unknown as T, [name]);
onChange(null as unknown as T, fieldPathId.path);
Copy link
Member Author

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

@heath-freenome heath-freenome merged commit a5421d3 into rjsf-team:main Oct 8, 2025
4 checks passed
@heath-freenome heath-freenome deleted the fix-4796 branch October 8, 2025 19:54
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.

Performance issue when using LayoutGrid with Live validation

2 participants