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

[Bug]: Crash in MultiSelect with undefined selectedItems #16052

Closed
2 tasks done
finken2 opened this issue Mar 25, 2024 · 1 comment · Fixed by #16076
Closed
2 tasks done

[Bug]: Crash in MultiSelect with undefined selectedItems #16052

finken2 opened this issue Mar 25, 2024 · 1 comment · Fixed by #16076
Labels
component: multi-select role: dev 🤖 severity: 4 Unrelated to a user task, has a workaround or does not need a workaround type: bug 🐛

Comments

@finken2
Copy link
Contributor

finken2 commented Mar 25, 2024

Package

@carbon/react

Browser

Chrome

Package version

v1.53.0

React version

v18.2.0

Description

This is admittedly user error, but it seems like it would be a good idea to protect against it.
If selectedItems has an array with undefined in it, this PR will try to read text from undefined and crash with the stack below:

Uncaught TypeError: Cannot read properties of undefined (reading 'text')
    at @carbon_react.js?v=72b18db9:100065:90
    at Array.map (<anonymous>)
    at @carbon_react.js?v=72b18db9:100065:71

I hit it b/c we had some bad test code, but figured it would be a good idea to just add some optional chaining in that MultiSelect code so it doesn't crash.

Reproduction/example

https://stackblitz.com/edit/github-caiwsw?file=src%2FApp.jsx

Steps to reproduce

Create a multiselect
in selectedItems, have an item that is undefined or null.

Suggested Severity

Severity 4 = Unrelated to a user task, has a workaround or does not need a workaround.

Application/PAL

IBM Cloud Satellite

Code of Conduct

@jesnajoseijk
Copy link
Contributor

jesnajoseijk commented Mar 26, 2024

@finken2 I think this would need an additional fix in sorting.js.We might need to add the optional chaining on calling the
localeCompare method.Have added that as well to the PR

@tay1orjones tay1orjones added severity: 3 User can complete task, and/or has a workaround role: dev 🤖 component: multi-select severity: 4 Unrelated to a user task, has a workaround or does not need a workaround and removed severity: 3 User can complete task, and/or has a workaround labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: multi-select role: dev 🤖 severity: 4 Unrelated to a user task, has a workaround or does not need a workaround type: bug 🐛
Projects
Status: ✅ Done
3 participants