-
Notifications
You must be signed in to change notification settings - Fork 416
Open
Description
Describe the bug
Starting from version 3.2.0, with React Material renderers, I observed that any keyboard input in any field triggers a rerender of the oneOf elements.
Expected behavior
The oneOf elements should rerender only when there is keyboard input within their own fields, as was happening in version 3.1.0
Steps to reproduce the issue
- Clone the react seed
- Add this
src/CustomTextrenderer that wraps theMaterialTextControlinserting aMath.random()to make the rerendering evidentimport { ControlProps, isStringControl, RankedTester, rankWith } from '@jsonforms/core'; import { withJsonFormsControlProps } from '@jsonforms/react'; import { Unwrapped } from '@jsonforms/material-renderers'; import React from 'react'; const { MaterialTextControl } = Unwrapped; export const CustomText = React.memo((props: ControlProps) => ( <> <MaterialTextControl {...props} /> {Math.random()} </> )); export const customTextTester: RankedTester = rankWith( 1+100, isStringControl ); export default withJsonFormsControlProps(CustomText);
- replace the
src/schema.jsonwith this, containing a text field and a oneOf:{ "definitions": { "address": { "type": "object", "title": "Address", "properties": { "street_address": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" } }, "required": [ "street_address", "city", "state" ] }, "user": { "type": "object", "title": "User", "properties": { "name": { "type": "string" }, "mail": { "type": "string" } }, "required": [ "name", "mail" ] } }, "type": "object", "properties": { "testText":{ "type": "string" }, "addressOrUser": { "oneOf": [ { "$ref": "#/definitions/address" }, { "$ref": "#/definitions/user" } ] } } } - Add the
CustomTextrenderer{ tester: customTextTester, renderer: CustomText }tosrc/App.tsx's array of renderers, comment theuischemainJsonFormselement (the default uischema is enough) - Start the application, fill the
Test Textfield and observe that everything is rerendering, oneOf included, even if there should be no reason for the oneOf to rerender - Now, switch to the JSONForms version v3.1.0:
git checkout 3ed669c5e6434919b090c7c9981f3c9a643c125c, and reinstall the dependenciesnpm install; repeat the steps at the previous point and observe that when fillingTest Textthere is no oneOf rerendering, as it should be.
Screenshots
No response
Which Version of JSON Forms are you using?
v3.3.0
Framework
React
RendererSet
Material
Additional context
No response