rjsf-team/react-jsonschema-form

oneOf + const is handled differently when nested in a property vs as a root object property

Open

#4963 opened on Feb 19, 2026

View on GitHub
 (9 comments) (0 reactions) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
bughelp wanted

Description

Prerequisites

What theme are you using?

mantine

Version

6.3.1

Current Behavior

It's possible there's something I don't understand about JSON Schema or RJSF here, but this seems like a bug to me.

This is with the following feature flag:

experimental_defaultFormStateBehavior={{
  constAsDefaults: 'always',
}}

The first schema will have the behavior of enforcing food equals "fish" if animal equals "Cat". Even if the user uses the dropdown to select a different value, it forces it back to the const value. The second schema is essentially the same schema, except nested inside a property nested. The above behavior is no longer observed.

Validation is not broken, but the UX behavior changes.

Working playground with the schema below:

{
  "type": "object",
  "properties": {
    "animal": {
      "enum": [
        "Cat",
        "Fish"
      ]
    },
    "food": {
      "type": "string",
      "enum": [
        "meat",
        "grass",
        "fish"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Cat"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "const": "fish"
          }
        },
        "required": [
          "food"
        ]
      }
    },
    {
      "required": [
        "animal"
      ]
    }
  ]
}

Bugged playground with the schema below:

{
  "type": "object",
  "properties": {
    "nested": {
      "type": "object",
      "properties": {
        "animal": {
          "enum": [
            "Cat",
            "Fish"
          ]
        },
        "food": {
          "type": "string",
          "enum": [
            "meat",
            "grass",
            "fish"
          ]
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "animal": {
                  "const": "Cat"
                }
              }
            },
            "then": {
              "properties": {
                "food": {
                  "const": "fish"
                }
              },
              "required": [
                "food"
              ]
            }
          },
          {
            "required": [
              "animal"
            ]
          }
        ]
      }
    }
  }
}

Expected Behavior

Consistent UX behavior whether the allOf is the root object or a nested object property.

Steps To Reproduce

Observable in the plaground via the two links above

Environment

- OS: Windows 11
- Node: 22.13.1
- npm: 11.7.0

Anything else?

No response

Contributor guide