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

[Autocomplete] 5.11.7 Introduced a Crashing Bug For This Configuration of Autocomplete #36114

Closed
2 tasks done
waful opened this issue Feb 9, 2023 · 1 comment · Fixed by #36116
Closed
2 tasks done
Assignees
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! regression A bug, but worse

Comments

@waful
Copy link

waful commented Feb 9, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:
https://codesandbox.io/s/compassionate-kapitsa-ouc9ml?file=/demo.tsx

Steps:

  1. Select any option on the Autocomplete options dropdown
  2. Immediately delete the option (backspace or clicking the X on the Chip both trigger the error as long as dropdown is not dismissed)
  3. Observe crashing error Cannot read properties of undefined (reading 'label') at https://github.com/mui/material-ui/blob/master/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js#L100 called from https://github.com/mui/material-ui/blob/master/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js#L473

Current behavior 😯

I expect the Autocomplete to not crash if I select the wrong option in the dropdown and immediately try to delete it

Expected behavior 🤔

No crashing, the selected option is deleted

Context 🔦

The three options specified in the CodeSandbox all need to be present for this issue to trigger: multiple, disableCloseOnSelect, and filterSelectedOptions. This issue was introduced in 5.11.7 by this PR: #35735

The source trigger is getOptionLabel(value[i]) here: https://github.com/mui/material-ui/blob/master/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js#L473

When you delete the option, value is now [] and so value[i] is undefined. When fed to getOptionLabel, it crashes because it expects option to not be undefined.

Your environment 🌎

npx @mui/envinfo
  System:
    OS: Windows 10 WSL Ubuntu 20.04
  Binaries:
    Node: 16.17.1
    Yarn: 1.22.19
    npm: 8.15.0
  Browsers:
    Brave v1.47.186
  npmPackages:
    @emotion/react: ^11.10.4 => 11.10.5
    @emotion/styled: ^11.10.4 => 11.10.5
    @mui/base:  5.0.0-alpha.116
    @mui/core-downloads-tracker:  5.11.8
    @mui/icons-material: ^5.10.6 => 5.11.0
    @mui/lab: ^5.0.0-alpha.118 => 5.0.0-alpha.119
    @mui/material: 5.11.7 => 5.11.7  // pinned to 5.11.7 after pinning to 5.11.6 and observing the bug does not exist
    @mui/private-theming:  5.11.7
    @mui/styled-engine:  5.11.8
    @mui/system:  5.11.8
    @mui/types:  7.2.3
    @mui/utils:  5.11.7
    @mui/x-date-pickers: ^5.0.4 => 5.0.17
    @types/react: ^18.0.21 => 18.0.27
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^4.8.3 => 4.9.5
@waful waful added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 9, 2023
@waful waful changed the title [Autocomplete] 5.11.7 Introduced a Crashing Bug For This Specific Configuration of Autocomplete [Autocomplete] 5.11.7 Introduced a Crashing Bug For This Configuration of Autocomplete Feb 9, 2023
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Feb 9, 2023
@michaldudak
Copy link
Member

Thanks for the detailed report. We'll fix it ASAP.

@michaldudak michaldudak added bug 🐛 Something doesn't work regression A bug, but worse and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! regression A bug, but worse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants