Skip to content

Boolean fields set to {} when mergeDefaultsIntoFormData is useDefaultIfFormDataUndefined #4709

@cdriscol

Description

@cdriscol

Prerequisites

What theme are you using?

core

Version

6.0.0-beta.12

Current Behavior

When using discriminated unions (oneOf/anyOf) with boolean properties that exist across multiple schema variants, switching between union options incorrectly sets undefined/missing boolean values to empty objects {}.

Specifically:

  1. Form has an optional boolean field that is missing or undefined
  2. User switches from Schema Variant A to Schema Variant B
  3. The boolean field gets set to {} instead of remaining undefined or getting a proper boolean default
  4. This breaks form validation and data integrity

Note: Existing boolean values (true/false) are preserved correctly - the bug only affects undefined/missing boolean fields.

Expected Behavior

Boolean fields that exist in multiple discriminated union variants should remain undefined or get proper default boolean values when switching between schema options, not get set to empty objects {}.

Steps To Reproduce

Live Playground Demo

Exact Steps:

  1. Add an array item (click the "+" button)
  2. Change the array type (use the dropdown to switch between typeA and typeB)
  3. Notice the validation errors and showField set to {} instead of boolean
  4. Error message shows: "showField must be boolean" but the field contains {}

Minimal Reproduction Schema

{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": { "const": "typeA" },
              "showField": { "type": "boolean" },
              "dataA": { "type": "string" }
            }
          },
          {
            "type": "object",
            "properties": {
              "type": { "const": "typeB" },
              "showField": { "type": "boolean" },
              "dataB": { "type": "string" }
            }
          }
        ]
      }
    }
  }
}

Form Data (initially empty):

{
  "items": []
}

Steps:

  1. Leave showField undefined (don't set any value)
  2. Switch union selector from "typeA" to "typeB"
  3. showField gets set to {} instead of remaining undefined

Environment

- OS: MacOS
- Node: 22
- npm: 10

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageInitial label given, to be assigned correct labels and assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions