Skip to content

Commit 70c3a03

Browse files
SuriGillepicfaace
authored andcommitted
fix: update schema to re-render when idschema changes (rjsf-team#1493)
* fix: update arrays correctly when changing index * fix: Update anyOf schema to correctly update items in an array * fix: update schema to re-render when idschema changes
1 parent 29c704e commit 70c3a03

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/components/fields/SchemaField.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,7 @@ function SchemaFieldRender(props) {
405405

406406
class SchemaField extends React.Component {
407407
shouldComponentUpdate(nextProps, nextState) {
408-
// if schemas are equal idSchemas will be equal as well,
409-
// so it is not necessary to compare
410-
return !deepEquals(
411-
{ ...this.props, idSchema: undefined },
412-
{ ...nextProps, idSchema: undefined }
413-
);
408+
return !deepEquals(this.props, nextProps);
414409
}
415410

416411
render() {

test/anyOf_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,53 @@ describe("anyOf", () => {
716716
expect(selects[1].value).eql("0");
717717
});
718718

719+
it("should correctly update inputs for anyOf inside array items after being moved down", () => {
720+
const schema = {
721+
type: "object",
722+
properties: {
723+
items: {
724+
type: "array",
725+
items: {
726+
type: "object",
727+
anyOf: [
728+
{
729+
properties: {
730+
foo: {
731+
type: "string",
732+
},
733+
},
734+
},
735+
{
736+
properties: {
737+
bar: {
738+
type: "string",
739+
},
740+
},
741+
},
742+
],
743+
},
744+
},
745+
},
746+
};
747+
748+
const { node } = createFormComponent({
749+
schema,
750+
formData: {
751+
items: [{}, {}],
752+
},
753+
});
754+
755+
const moveDownBtns = node.querySelectorAll(".array-item-move-down");
756+
Simulate.click(moveDownBtns[0]);
757+
758+
const strInputs = node.querySelectorAll(
759+
"fieldset .field-string input[type=text]"
760+
);
761+
762+
Simulate.change(strInputs[1], { target: { value: "bar" } });
763+
expect(strInputs[1].value).eql("bar");
764+
});
765+
719766
it("should correctly render mixed types for anyOf inside array items", () => {
720767
const schema = {
721768
type: "object",

0 commit comments

Comments
 (0)