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

[TreeView] RichTreeView throws error when using dynamic items #12510

Closed
jroebu14 opened this issue Mar 20, 2024 · 3 comments · Fixed by #12512
Closed

[TreeView] RichTreeView throws error when using dynamic items #12510

jroebu14 opened this issue Mar 20, 2024 · 3 comments · Fixed by #12512
Assignees
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module!

Comments

@jroebu14
Copy link

jroebu14 commented Mar 20, 2024

Steps to reproduce

Link to live example: (required)
https://codesandbox.io/p/sandbox/cool-leftpad-g472qt?file=%2Fsrc%2FDemo.tsx%3A44%2C5

Steps:

  1. Filter tree items by clicking the "Filter items" button.
  2. Go back to the initial tree items by clicking the "Unfilter items" button
  3. Observe an exception is thrown:
Cannot read properties of undefined (reading 'label')
    at processItem (https://g472qt.csb.app/node_modules/
mui/x-tree-view/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js:41:57

Current behavior

When updating items prop to achieve filtering of the original items and then updating the items prop to revert to the original items then an error is thrown.

Error comes from this line of code.

Expected behavior

Any kind of updating to the items prop should not throw an error.

Context

Filtering of tree items powered by a search text box.

Your environment

npx @mui/envinfo

Error occurs on any browser.

  System:
    OS: macOS 14.4
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 122.0.6261.129
    Edge: 122.0.2365.92
    Safari: 17.4
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.4 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/base:  5.0.0-beta.38 
    @mui/core-downloads-tracker:  5.15.12 
    @mui/icons-material:  5.15.13 
    @mui/lab:  5.0.0-alpha.167 
    @mui/material:  5.15.12 
    @mui/private-theming:  5.15.12 
    @mui/styled-engine:  5.15.11 
    @mui/styles:  5.15.12 
    @mui/system:  5.15.12 
    @mui/types:  7.2.13 
    @mui/utils:  5.15.13 
    @mui/x-tree-view:  6.17.0 
    @types/react:  18.2.65 
    react:  18.2.0 
    react-dom:  18.2.0 
    styled-components:  5.3.11 
    typescript: ~5.4.0 => 5.4.2 

Search keywords: richtreeview dynamic items

@jroebu14 jroebu14 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 20, 2024
@flaviendelangle
Copy link
Member

Hi,

Thanks for your feedback.
I think the problem here is that `useTreeViewKeyboardNavigation uses an outdated version of the items (the filtered one) so it fails to access the label of the newly created item.
I'll see how to solve that 👍

@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 20, 2024
@flaviendelangle flaviendelangle self-assigned this Mar 20, 2024
@jroebu14
Copy link
Author

jroebu14 commented Mar 20, 2024

Hi @flaviendelangle 👋

Ah ok that makes sense.

Thanks for looking into it!

@flaviendelangle flaviendelangle changed the title RichTreeView throws error when using dynamic items [TreeView] RichTreeView throws error when using dynamic items Mar 20, 2024
Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @jroebu14?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

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: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module!
Projects
None yet
2 participants