[internal] Make grid list navigation tree-shakeable#4944
Open
atomiks wants to merge 1 commit into
Open
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,325.32 ms -62.38 ms(-4.5%) | Renders: 50 (+0) | Paint: 2,012.71 ms -85.13 ms(-4.1%) No significant changes — 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. |
369c190 to
6c0f5de
Compare
`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.
6c0f5de to
2d2d4ed
Compare
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 in thegridoption, so menu, context menu, and select can tree-shake the grid path out while combobox/autocomplete keep grid behavior.Changes
gridNavigation.ts.gridoption.colsoption fromuseListNavigation.Bundle size
Measured with
pnpm size:snapshot.@base-ui/react/select-3,268 B-1,204 B@base-ui/react/context-menu-3,281 B-1,205 B@base-ui/react/menu-3,268 B-1,204 B@base-ui/react/autocomplete+74 B+37 B@base-ui/react/combobox+76 B+41 B@base-ui/react+83 B+8 B