Skip to content

Empty enum is blocking dependency after v5.5.1  #4357

Open
@cewald

Description

@cewald

Prerequisites

  • I have searched the existing issues
    I understand that providing a SSCCE example is tremendously useful to the maintainers.
    I have read the documentation
    Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.

What theme are you using?

mui

Version

5.5.1

Current Behavior

If I have a first field with an enum and a second dependant field that holds an empty enum at first but should get filled when the first field gets selected, the second dependant field isn't getting filled as long as the enum of the first field is initially empty. If put an initial value in the second dependant fields enum it works fine.

This error came with the version update 5.1.1.

Expected Behavior

Update the dependant field even tough it is an empty enum first.

Steps To Reproduce

You can reproduce it in the playground with the following two schemas.

This is the working one (with an initial string in the dependant enum) (Playground link)

{
  "type": "object",
  "properties": {
    "firstField": {
      "type": "string",
      "title": "First Field",
      "enum": [
        "Value One",
        "Value Two"
      ]
    },
    "dependantField": {
      "title": "Dependant Field",
      "enum": [
        "Select a value in First field"
      ],
      "readOnly": true
    }
  },
  "required": [
    "firstField",
    "dependantField"
  ],
  "dependencies": {
    "firstField": {
      "oneOf": [
        {
          "properties": {
            "firstField": {
              "enum": [
                "Value One"
              ]
            },
            "dependantField": {
              "enum": [
                "More Values",
                "Even More Values",
                "Enough"
              ],
              "readOnly": false
            }
          }
        },
        {
          "properties": {
            "firstField": {
              "enum": [
                "Value Two"
              ]
            },
            "dependantField": {
              "enum": [
                "Other Values",
                "Even More Other Values",
                "Enough now"
              ],
              "readOnly": false
            }
          }
        }
      ]
    }
  }
}

And with this the one its broken since the update (empty initial enum) and wont update the second dependant field: (Playground link)

{
  "type": "object",
  "properties": {
    "firstField": {
      "type": "string",
      "title": "First Field",
      "enum": [
        "Value One",
        "Value Two"
      ]
    },
    "dependantField": {
      "title": "Dependant Field",
      "enum": [],
      "readOnly": true
    }
  },
  "required": [
    "firstField",
    "dependantField"
  ],
  "dependencies": {
    "firstField": {
      "oneOf": [
        {
          "properties": {
            "firstField": {
              "enum": [
                "Value One"
              ]
            },
            "dependantField": {
              "enum": [
                "More Values",
                "Even More Values",
                "Enough"
              ],
              "readOnly": false
            }
          }
        },
        {
          "properties": {
            "firstField": {
              "enum": [
                "Value Two"
              ]
            },
            "dependantField": {
              "enum": [
                "Other Values",
                "Even More Other Values",
                "Enough now"
              ],
              "readOnly": false
            }
          }
        }
      ]
    }
  }
}

Environment

- OS: Debian, Ubuntun, MacOSX
- Node: 20.17.0
- npm: 10.8.2

Anything else?

I guess I'v nailed it down to this two commit:
f34a7a2
ff46301 <- its this one

And this change in the changelog:
https://github.com/rjsf-team/react-jsonschema-form/blob/main/CHANGELOG.md#551

In v5.5.0 my example is working in v5.5.1 not.

Activity

added
needs triageInitial label given, to be assigned correct labels and assigned
on Oct 30, 2024
cewald

cewald commented on Oct 30, 2024

@cewald
Author

Afaik in the change above const isValid = validator.isValid(conditionSchema, formData, rootSchema); returns now false and the before term validator.validateFormData(formData, conditionSchema) returns true – I try to find why its considered different. FYI I'm using ajv8 as validator.

heath-freenome

heath-freenome commented on Nov 1, 2024

@heath-freenome
Member

Afaik in the change above const isValid = validator.isValid(conditionSchema, formData, rootSchema); returns now false and the before term validator.validateFormData(formData, conditionSchema) returns true – I try to find why its considered different. FYI I'm using ajv8 as validator.

The change you are pointing out was done to help improve performance since isValid() is simpler and uses caching better than validateFormData(). If you patch it locally back to the old implementation, does it work again? If so, maybe we can write a test to catch that issue in isValid() and fix it?

cewald

cewald commented on Nov 1, 2024

@cewald
Author

I see – yes, if I patch it back, it is working.

heath-freenome

heath-freenome commented on Nov 5, 2024

@heath-freenome
Member

Hmmm, @nickgros Any thoughts on whether we roll back this change?

nickgros

nickgros commented on Nov 5, 2024

@nickgros
Contributor

Rolling it back seems appropriate with a test to verify that this is fixed. If someone needs the performance optimizations provided by isValid, it would be on them to to ensure this case still works.

cewald

cewald commented on Dec 10, 2024

@cewald
Author

Hey hey, any progress or decision?
I would be fine with a rollback ;)

heath-freenome

heath-freenome commented on Dec 13, 2024

@heath-freenome
Member

@cewald Yes, let's roll it back. Are you willing to push up the PR for that?

cewald

cewald commented on Dec 16, 2024

@cewald
Author

@heath-freenome alright no problem, i opened one: #4418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @cewald@nickgros@heath-freenome

      Issue actions

        Empty enum is blocking dependency after v5.5.1 · Issue #4357 · rjsf-team/react-jsonschema-form