Skip to content

Conversation

cdriscol
Copy link
Contributor

@cdriscol cdriscol commented Aug 9, 2025

Fixes #4709: Boolean fields now remain undefined or get proper defaults when switching between schema variants with mergeDefaultsIntoFormData set to useDefaultIfFormDataUndefined

Reasons for making this change

This PR fixes a critical bug where boolean fields in discriminated unions (oneOf/anyOf) were incorrectly being set to empty objects {} instead of remaining undefined or receiving proper boolean default values when users switch between schema options.

Problem:

  • When using mergeDefaultsIntoFormData: "useDefaultIfFormDataUndefined"
  • Boolean fields that exist across multiple oneOf/anyOf schema variants
  • Switching from one schema variant to another causes undefined boolean fields to be set to {}
  • This breaks form validation and data integrity
  • Only affects undefined/missing boolean fields (existing true/false values were preserved correctly)

Solution:
Updated the form data merging logic in @rjsf/utils to properly handle boolean field types when sanitizing data for new schemas, ensuring undefined boolean fields remain undefined or get appropriate default values instead of being converted to empty objects.

Testing:

  • Added comprehensive test cases covering the oneOf boolean field scenarios
  • Verified existing boolean values (true/false) continue to work correctly
  • Ensured other field types are not affected by the changes

Fixes #4709

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

@cdriscol cdriscol marked this pull request as ready for review August 9, 2025 06:16
@cdriscol cdriscol changed the title Fix boolean fields incorrectly set to {} in oneOf/anyOf schemas fix (utils): Fix boolean fields incorrectly set to {} in oneOf/anyOf schemas Aug 9, 2025
@cdriscol cdriscol changed the title fix (utils): Fix boolean fields incorrectly set to {} in oneOf/anyOf schemas fix(utils): #4709 fix boolean fields incorrectly set to {} in oneOf/anyOf schemas Aug 9, 2025
Fixes rjsf-team#4709: Boolean fields now remain undefined or get proper defaults when switching between schema variants with mergeDefaultsIntoFormData set to useDefaultIfFormDataUndefined
@cdriscol cdriscol force-pushed the fix/boolean-fields-oneOf-issue-4709 branch from d2655f0 to 7453d81 Compare August 11, 2025 18:19
…Of fix

Address review feedback by documenting the potentially breaking change
where undefined primitive fields in oneOf/anyOf schemas no longer
incorrectly become {} objects when using mergeDefaultsIntoFormData.

This affects all primitive field types (boolean, string, number, etc.),
not just boolean fields.

Fixes feedback from PR rjsf-team#4710
@heath-freenome heath-freenome merged commit b36edc3 into rjsf-team:main Aug 11, 2025
4 checks passed
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Aug 12, 2025
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.

Boolean fields set to {} when mergeDefaultsIntoFormData is useDefaultIfFormDataUndefined

2 participants