[internal] Make grid list navigation tree-shakeable#4944
Draft
atomiks wants to merge 1 commit into
Draft
Conversation
`useListNavigation`'s grid path (`cols > 1`) statically imported the grid helpers (`createGridCellMap`/`getGridNavigatedIndex`/`getGridCellIndexOfCorner`/ `getGridCellIndices`), so every list consumer bundled ~1.2 KB gzip of grid code. The only consumer that ever enables grid is `AriaCombobox` (combobox/autocomplete in grid mode); menu, context-menu, and select are 1-D lists that never reach it. Extract the grid branch into `hooks/gridNavigation.ts` and inject it via an optional `gridNavigation` prop that only grid-capable consumers supply. Non-grid consumers no longer reference the grid helpers, so they tree-shake out: - menu -1177 B gz - context-menu -1175 B gz - select -1152 B gz - combobox +79 B gz (keeps grid; module-boundary cost) - autocomplete +70 B gz (keeps grid; module-boundary cost) Net -3355 B gz across the popup family. Behavior is unchanged; the grid test fixtures and `useListNavigation` grid tests now inject `gridNavigation` exactly as `AriaCombobox` does.
commit: |
Bundle size
PerformanceTotal duration: 1,109.30 ms +11.27 ms(+1.0%) | Renders: 50 (+0) | Paint: 1,668.92 ms -1.05 ms(-0.1%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This removes grid navigation code from non-grid
useListNavigationconsumers. Grid-capable consumers pass the grid handler separately, so menu, context menu, and select can tree-shake the grid path out while combobox/autocomplete keep grid behavior.Changes
gridNavigation.ts.gridNavigationfrom combobox and grid test fixtures.Bundle size
Measured with
pnpm size:snapshot.@base-ui/react/select-3,259 B-1,193 B@base-ui/react/context-menu-3,272 B-1,186 B@base-ui/react/menu-3,259 B-1,186 B@base-ui/react/autocomplete+78 B+40 B@base-ui/react/combobox+80 B+41 B@base-ui/react+87 B+71 B