Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/eight-hats-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

perf(TreeView): Optimize typeahead with startTransition to prevent input lag

Wrapped the expensive typeahead search operation in `startTransition` to mark it as low-priority, keeping keystroke handling responsive while deferring the focus search. This improves performance on large trees with thousands of items.
7 changes: 5 additions & 2 deletions packages/react/src/TreeView/useTypeahead.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, {startTransition} from 'react'
import useSafeTimeout from '../hooks/useSafeTimeout'
import {getAccessibleName} from './shared'
import {useTreeItemCache} from './useTreeItemCache'
Expand Down Expand Up @@ -71,7 +71,10 @@ export function useTypeahead({containerRef, onFocusChange}: TypeaheadOptions) {

// Update the existing search value with the new key press
searchValue.current += event.key
focusSearchValue(searchValue.current)
// Defer the expensive search operation to avoid blocking user input
startTransition(() => {
focusSearchValue(searchValue.current)
})

// Reset the timeout
safeClearTimeout(timeoutRef.current)
Expand Down