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

Adding isSearchable to MUI Select with loadOptions breaks loading #1448

Closed
haydenlinder opened this issue Mar 21, 2024 · 2 comments · Fixed by #1449
Closed

Adding isSearchable to MUI Select with loadOptions breaks loading #1448

haydenlinder opened this issue Mar 21, 2024 · 2 comments · Fixed by #1449
Assignees
Labels
bug Something isn't working common released

Comments

@haydenlinder
Copy link

Scope: <DESCRIBE SCOPE OF THIS ISSUE, i.e.: PF4 mapper, Form renderer>

This is for MUI mapper.

Description

Adding isSearchable to MUI Select with loadOptions breaks loading. When you type your search, none of the options show up.

Schema

You can reproduce here by adding isSearchable: true.

export default {
  "fields": [
    {
      "component": "select",
      "label": "Select",
      "name": "select",
      "simpleValue": true,
      "options": [],
      "isSearchable": true,
      "loadOptions":  () =>
      new Promise((res) =>
        setTimeout(
          () =>
            res([
              { value: 'first-option', label: 'First async option' },
              { value: 'second-option', label: 'Second async option' }
            ]),
          2500
        )
      ) 
    }
  ]
};

<If it's possible, please provide a schema which reproduces the issue>

@Hyperkid123 Hyperkid123 self-assigned this Mar 21, 2024
@Hyperkid123
Copy link
Member

@haydenlinder thanks for the issue. This one is "fun".

The problem is this: c0eb916#diff-e562c6a6573e48431bc65138f034bae8830db07209229974efa6f1adc9736f8dR15

This was a change to move away from defaultProps to inline default props. However, there is one pretty big side effect.

Component.defaultProps props references never changes. But {options = []} in the function arguments changes on each render. And because [] !== [] it triggers a hook that resets the options to an empty array. We can get around it by using memo and deep equal function. But it's pretty sneaky and will be less efficient.

@rvsia rvsia added the released label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working common released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants