You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TreeView: focusing a parent item re-renders its expanded subtree #8718
Part of #8676 (P1). Measure with #8714 before and after.
Problem
TreeView/TreeView.tsx:501 passes a new object to ItemContext.Provider on every Item render. The isFocused state at :312 changes on focus and blur. So focusing or blurring a parent re-renders every descendant that reads ItemContext. TreeView.tsx is excluded from the React Compiler, so nothing memoizes the value automatically.
Measured: summed update-commit time after tabbing to an expanded parent, median of 7 runs:
Children
Commit time
10
0.5 ms
100
2.7 ms
400
9.8 ms
The cost grows linearly with subtree size.
#8684 (merged) reduced mount and hydration cost but didn't change this. #8682 (open) changes only TreeView CSS.
Proposed fix
Memoize the ItemContext value with useMemo, or enable the React Compiler for TreeView.tsx (#8721). The fix must work on React 18 and 19.
Acceptance criteria
Focusing an expanded parent doesn't re-render its children. Add a test that counts renders.
Keyboard navigation, typeahead, expand and collapse, and async loading behave the same as before.
Activity