Skip to content

Unexpected oneOf re-rendering when filling other schema fields [React Material] #2342

Open
@andrecchia

Description

@andrecchia

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/CustomText renderer that wraps the MaterialTextControl inserting a Math.random() to make the rerendering evident
      import {
          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.json with 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 CustomText renderer { tester: customTextTester, renderer: CustomText } to src/App.tsx's array of renderers, comment the uischema in JsonForms element (the default uischema is enough)
  • Start the application, fill the Test Text field 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 dependencies npm install; repeat the steps at the previous point and observe that when filling Test Text there 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions