Skip to content

Conversation

The-Zona-Zoo
Copy link
Contributor

@The-Zona-Zoo The-Zona-Zoo commented Sep 2, 2025

Reasons for making this change

This change fixes #4756 where array items shared object references when using discriminated unions (oneOf) combined with minItems > 0 and undefined initial form data.

Problem

When arrays needed to be populated to meet minItems requirements, the Array.fill() method created shared object references instead of independent instances. This caused form field changes in one array item to unintentionally affect other array items.

Impact

  • Affected scenarios: Discriminated unions + arrays with minItems > 0 + undefined initial form data
  • User experience: Form fields unexpectedly changing values when editing different array items
  • Frequency: Occurs consistently in the specific combination of conditions above

Testing

  • Added comprehensive test coverage to getDefaultFormStateTest.ts
  • Tests verify object independence and cover edge cases
  • Maintains 100% test coverage requirement for utils package
  • Tested in local playground website

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

The-Zona-Zoo and others added 2 commits September 2, 2025 14:54
…minItems

Fixes rjsf-team#4756

When arrays with minItems > 0 were populated for discriminated unions (oneOf with discriminator),
the Array.fill() method created shared object references instead of independent instances.
This caused form field changes to affect multiple array items simultaneously.

Solution:
- Replace Array.fill() with Array.from() in getArrayDefaults function
- Array.from() creates independent object instances for each array item
- Maintains existing behavior while fixing the reference sharing bug

Added comprehensive test coverage for:
- Basic object independence in arrays
- Nested object scenarios
- Exact reproduction case from issue rjsf-team#4756
- Integration with discriminated union schemas
@heath-freenome heath-freenome merged commit fbf6324 into rjsf-team:main Sep 3, 2025
4 checks passed
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Sep 3, 2025
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this pull request Sep 3, 2025
Fixes rjsf-team#4757 by switching the `cjs` build process to produce `.cjs` files instead of `.js` files in the distribution
- Updated all `package.json` files to change the `build:cjs` script to produce `.cjs` files
- Updated the `v6.x upgrade guide.md` and `CHANGELOG.md` to document the change
heath-freenome added a commit that referenced this pull request Sep 3, 2025
* Fix 4757 by generating .cjs files for the cjs distro
Fixes #4757 by switching the `cjs` build process to produce `.cjs` files instead of `.js` files in the distribution
- Updated all `package.json` files to change the `build:cjs` script to produce `.cjs` files
- Updated the `v6.x upgrade guide.md` and `CHANGELOG.md` to document the change

* - Fixed the `require` statements in the `exports` to use `.cjs`
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.

Object reference sharing in arrays when using discriminated unions with minItems
2 participants