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

Tree: Lazy loaded tree crashes when using keyboard navigation (right arrow) to expand #6049

Closed
espentveit opened this issue Feb 27, 2024 · 2 comments · Fixed by #6053
Closed
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@espentveit
Copy link

espentveit commented Feb 27, 2024

Describe the bug

Selecting a node, then pressing the right arrow button crashes the tree when the tree is lazy loaded. Issue occurs in demo as well.

Cannot read properties of undefined (reading 'children')
at tree.esm.js:1094:1
at tree.esm.js:150:1

Code:

useUpdateEffect(function () {
    if (childFocusEvent.current) {
      var event = childFocusEvent.current;
      var nodeElement = event.target.getAttribute('data-pc-section') === 'toggler' ? event.target.closest('[role="treeitem"]') : event.target;
      var listElement = nodeElement.children[1];
      var childElement = listElement.children[0];  // crashes here
      nodeElement.tabIndex = '-1';
      childElement.tabIndex = '0';
      childElement.focus();
      childFocusEvent.current = null;
    }
  }, [expandedKeys]);

Reproducer

No response

PrimeReact version

10.5.1

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome 121

Steps to reproduce the behavior

  1. Click first node with children in a lazy loaded tree
  2. Press the right arrow key on the keyboard to expand node
  3. Crash

Expected behavior

The tree should expand the node instead of crashing

@espentveit espentveit added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 27, 2024
melloware added a commit to melloware/primereact that referenced this issue Feb 28, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 28, 2024
@melloware melloware self-assigned this Feb 28, 2024
@melloware melloware added this to the 10.5.2 milestone Feb 28, 2024
@melloware
Copy link
Member

Thanks for reporting. Fixed for next release.

@espentveit
Copy link
Author

Thank you for the fix.

melloware added a commit to melloware/primereact that referenced this issue Feb 28, 2024
melloware added a commit to melloware/primereact that referenced this issue Feb 28, 2024
nitrogenous added a commit that referenced this issue Mar 18, 2024
Fix #6049: Tree lazy mode crash on arrow right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants