Skip to content

perf(tree): flatten rows and window large trees - #62

Merged
praisethemoon merged 2 commits into
mainfrom
sch/tree-fix
Sep 10, 2026
Merged

praisethemoon merged 2 commits into
mainfrom
sch/tree-fix

Conversation

@praisethemoon

@praisethemoon praisethemoon commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Tree used to render nodes recursively, so every expanded node stayed in the DOM
and each click re-rendered the whole subtree. Rows are now one flat list, and a
tree with a bounded height mounts only the rows in view.

  • New props: maxHeight, fillHeight, estimatedRowHeight, overscan, disableVirtualization
  • Rows are memoised, so a selection re-renders two rows instead of all of them
  • Keyboard navigation and ARIA now work off the flat row list
  • Docs page and a 22,620-node Storybook story added
  • REMOVED: Node expansion animation
  • Closes Tree mounts collapsed children | DOM is O(all nodes), not O(visible) #60

Risk level:

  • Low risk (docs, tests, minor fixes)
  • Medium risk (above average work, refactors)
  • High risk (infra, critical changes)

Tree rendered nodes recursively, so every expanded node stayed mounted and each
expand or selection re-rendered the whole subtree. Rows are now a flat list and
only the slice inside the viewport exists.

- flattenTree walks the visible nodes once, emitting rows carrying depth,
  parent index, sibling position and a guideMask, so a row draws its own edge
  guides without its ancestors being mounted
- window rows with @tanstack/react-virtual whenever the tree is given a bounded
  height; new maxHeight, fillHeight, estimatedRowHeight, overscan and
  disableVirtualization props
- memoise the row component and keep expansion/selection out of context, so a
  selection re-renders two rows rather than every mounted one
- normalise a controlled expandedKeys array into a Set once per real change
  rather than once per render
- roving tabindex with index-based keyboard navigation, scrolling an unmounted
  target into the window before focusing it
- per-row aria-level/posinset/setsize in place of the nested role="group"
  wrappers, keeping treeitems directly under the tree
- a custom expandIcon on a leaf no longer toggles it into expandedKeys
- add Tree.childMounting.test.tsx and a 22,620-node LargeTree story

@jonah-iden jonah-iden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@praisethemoon
praisethemoon merged commit 67b2a25 into main Sep 10, 2026
1 check passed
@jonah-iden
jonah-iden deleted the sch/tree-fix branch September 10, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree mounts collapsed children | DOM is O(all nodes), not O(visible)

2 participants