Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a memoized component as custom widget raise an "Unsupported widget definition" #2039

Closed
1 of 3 tasks
lucataglia opened this issue Sep 8, 2020 · 3 comments
Closed
1 of 3 tasks

Comments

@lucataglia
Copy link

Prerequisites

Description

Using a memoized component (React.memo(Component)) as custom widget raise the following error:

utils.js:210 Uncaught Error: Unsupported widget definition: object
    at getWidget (utils.js:210)
    at getWidget (utils.js:224)
    at BooleanField (BooleanField.js:52)

I investigated the source code I saw that into the utils.js file there is an if statement that fails to recognize the memoized component:

// utils.js, line 201-203. ReactIs.isMemo(widget) gives false as result
if (typeof widget === "function" || ReactIs.isForwardRef(_react["default"].createElement(widget)) || ReactIs.isMemo(widget)) {
    return mergeOptions(widget);
  }

Googling around I found out that into the ReactIs library the behavior of the isMemo method was recently changed: #PR 17278

I'm wondering if also the react-jsonschema-form library has to change how it checks that conditions. Removing the React.memo that wrap my component makes the "Unsupported widget definition" error disappear.

In my code I'm trying to use a custom CheckboxWidget.

Steps to Reproduce

  1. Create a memoized component e.g. const MemoizedComponent = React.memo(/* could be also a silly div*/)
  2. Use that component as custom widget e.g. { CheckboxWidget: MemoizedComponent }
  3. Render the form

Expected behavior

A memoized component shouldn't breaks the page

Actual behavior

Use e memoized component as custom widget breaks the page

Version

react: "16.13.1"
react-jsonschema-form: "2.0.0-alpha.1"

@adam-beck
Copy link
Contributor

Here is a CRA demonstrating the issue with the latest react-jsonschema-form: https://github.com/adam-beck/react-jsonschema-form/tree/investigate-2039-part2

@lucataglia
Copy link
Author

Is there any news about that bug ?

@stale
Copy link

stale bot commented Aug 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Aug 30, 2022
@stale stale bot closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants