Skip to content

TreeView: focusing a parent item re-renders its expanded subtree #8718

Open

Description

@mattcosta7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions