Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/utils

- Short-circuit `File` and `Date` constructor access in isObject to optimize performance in scenarios where `globalThis` is a `Proxy` that incurs overhead for each class constructor access ([#4413](https://github.com/rjsf-team/react-jsonschema-form/pull/4413)). Fixes [#4409](https://github.com/rjsf-team/react-jsonschema-form/issues/4409)
- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies ([#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418)). Fixes [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357)

## @rjsf/validator-ajv8

Expand Down
1 change: 1 addition & 0 deletions packages/core/test/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ describeRepeated('Form common', (createFormComponent) => {

it('should work with oneOf', function () {
const schema = {
$schema: 'http://json-schema.org/draft-06/schema#',
type: 'object',
properties: {
connector: {
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/schema/retrieveSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ export function withExactlyOneSubschema<
[dependencyKey]: conditionPropertySchema,
},
} as S;
return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
const { errors } = validator.validateFormData(formData, conditionSchema);
return errors.length === 0 || expandAllBranches;
}
return false;
});
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/test/schema/getDefaultFormStateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3930,13 +3930,13 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
]);
});
it('should populate defaults for nested dependencies in arrays when matching enum values in oneOf', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
true, // First oneOf... first === first
false, // Second oneOf... second !== first
false, // First oneOf... first !== second
true, // Second oneOf... second === second
data: [
{ errors: [], errorSchema: {} }, // First oneOf... first === first
{ errors: [{ stack: 'error' }], errorSchema: {} }, // Second oneOf... second !== first
{ errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... first !== second
{ errors: [], errorSchema: {} }, // Second oneOf... second === second
],
});
const schema: RJSFSchema = {
Expand Down
56 changes: 28 additions & 28 deletions packages/utils/test/schema/retrieveSchemaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {

describe('with $ref in oneOf', () => {
it('should retrieve referenced schemas', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
false, // First oneOf... second !== first
true, // Second oneOf... second === second
data: [
{ errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... second !== first
{ errors: [], errorSchema: {} }, // Second oneOf... second === second
],
});
const schema: RJSFSchema = {
Expand Down Expand Up @@ -576,11 +576,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {

describe('true condition', () => {
it('should add `first` properties given `first` data', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
true, // First dependency... first === first
false, // Second dependency... second !== first
data: [
{ errors: [], errorSchema: {} }, // First dependency... first === first
{ errors: [{ stack: 'error' }], errorSchema: {} }, // Second dependency... second !== first
],
});
const schema: RJSFSchema = {
Expand All @@ -598,11 +598,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {
});

it('should add `second` properties given `second` data', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
false, // First dependency... first !== second
true, // Second dependency... second === second
data: [
{ errors: [{ stack: 'error' }], errorSchema: {} }, // First dependency... first !== second
{ errors: [], errorSchema: {} }, // Second dependency... second === second
],
});
const schema: RJSFSchema = {
Expand All @@ -628,13 +628,13 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {
});

it('should not include nested dependencies that should be hidden', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
false, // employee_accounts oneOf ... - fail
true, // update_absences first oneOf... success
false, // update_absences second oneOf... fail
false, // update_absences third oneOf... fail
data: [
{ errors: [{ stack: 'error' }], errorSchema: {} }, // employee_accounts oneOf ... - fail
{ errors: [], errorSchema: {} }, // update_absences first oneOf... success
{ errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences second oneOf... fail
{ errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences third oneOf... fail
],
});
const formData = {
Expand All @@ -656,13 +656,13 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {
});

it('should include nested dependencies that should not be hidden', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
true, // employee_accounts oneOf... success
true, // update_absences first oneOf... success
false, // update_absences second oneOf... fail
false, // update_absences third oneOf... fail
data: [
{ errors: [], errorSchema: {} }, // employee_accounts oneOf... success
{ errors: [], errorSchema: {} }, // update_absences first oneOf... success
{ errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences second oneOf... fail
{ errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences third oneOf... fail
],
});
const formData = {
Expand Down Expand Up @@ -698,11 +698,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {

describe('with $ref in dependency', () => {
it('should retrieve the referenced schema', () => {
// Mock isValid so that withExactlyOneSubschema works as expected
// Mock errors so that withExactlyOneSubschema works as expected
testValidator.setReturnValues({
isValid: [
false, // First oneOf... fail
true, // Second oneOf... success
data: [
{ errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... fail
{ errors: [], errorSchema: {} }, // Second oneOf... success
],
});
const schema: RJSFSchema = {
Expand Down
Loading