Skip to content

[virtualizer] Create the standalone Virtualizer component - #5466

Open
michaldudak wants to merge 67 commits into
mui:masterfrom
michaldudak:virtualizer-standalone
Open

michaldudak wants to merge 67 commits into
mui:masterfrom
michaldudak:virtualizer-standalone

Conversation

@michaldudak

@michaldudak michaldudak commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Adds a virtualizer to Base UI: a component that renders only the items in and around the viewport, so a list over a large collection mounts a window of items instead of all of them.

Built on #5414 — its commits are included here, so that PR does not need to be read or merged first. #5173 and #5414 are superseded by this one.

The component

import { Virtualizer } from '@base-ui/react/virtualizer';

<Virtualizer items={items} getItemKey={(item) => item.id} role="listbox">
  {(item, index, itemProps) => (
    <div {...itemProps} role="option">{item.name}</div>
  )}
</Virtualizer>

It is the scroll container, and it takes the collection either from its own items prop, as above, or from a surrounding list that publishes one. Inside <Combobox.List> it needs neither items nor keyboard wiring:

<Combobox.List>
  <Virtualizer>
    {(item) => <Combobox.Item value={item}>{item.name}</Combobox.Item>}
  </Virtualizer>
</Combobox.List>

Those are the same component, and the two sources are what the three commits build in turn: virtualization for the combobox, then the same windowing as a component any list can publish a host for, then the standalone items mode.

What it takes care of

Items that are not mounted still belong to the list. Keyboard navigation moves through the whole collection, the getDisabled option of Combobox.createItems() decides disabled state for items that were never rendered, and every rendered item carries the collection metadata assistive technology needs — supplied through the list's own item component, or as the third argument of the item renderer for a list that has none.

Heights are estimated until measured, and a static estimatedItemHeight is refined with the running average of the items measured so far, so the scrollbar settles without scrolling through the collection. Around that sits the geometry a list needs and an engine alone does not give you: scroll anchoring so a measurement landing above the viewport does not move what the reader is looking at, a retained row for a highlight outside the window so it can still be selected, scrollport padding treated the way a plain scrolling list treats it, and a geometry refresh deferred until a scroll gesture ends.

Props worth calling out

items The collection. Omit it inside a list that supplies one.
activeIndex The active item, kept mounted outside the window so it can hold focus or be referenced by aria-activedescendant. An index alone scrolls it into view; { index, scroll: false } leaves the viewport alone for a highlight following the pointer; align says where a scrolled item lands.
totalItems Size of the whole collection when the items given are one page of it, reported as aria-setsize. -1 for a size not yet known.
onEndReached Fires when the window reaches the end, for loading the next page. Once per arrival, arming again when the collection grows. endReachedThreshold moves it earlier.
trailing Content after the last item, inside the scroll container: it scrolls with the items and is measured into the scrollable height, rather than being pinned below the list.
actionsRef scrollToIndex(index, { align }), and remeasure() to discard heights taken under a layout that has since changed — a breakpoint, a font swap — while keeping the scroll position.

Keeping the scroll decision inside activeIndex rather than in a prop of its own is deliberate: whether an activation should scroll depends on what caused it, not on which item ended up active, and two separate props could disagree.

Keyboard and accessibility

The scroll container is deliberately not a tab stop. Focus stays in the input and the list is driven by aria-activedescendant, so making it focusable would put Tab into the list instead of dismissing the popup. To make that a complete keyboard path rather than a trap, Page Down and Page Up now move the highlight ten items at a time, and the list scrolls to follow — reaching items that were never rendered, which no amount of scrolling could do. That lives in list navigation, so Select and Menu page the same way.

Automated checks flag any scrollable region that cannot be focused, so this container is reported by rules such as axe's scrollable-region-focusable. The docs say why it is expected and that it should be suppressed for this element: the rule cannot see the keyboard path that replaces it.

The same reasoning decides what trailing is for. A list may only contain options, so that content must stay out of the accessibility tree, with the state it stands for conveyed by aria-busy and a live region. Interactive affordances — a create-new button, say — belong outside the list, where they are in the tab order and can actually be reached.

Grouped collections

A grouped collection — an array of groups, each with an items array, the same shape the list components take — is passed to items together with renderGroupHeader:

<Combobox.Root items={groups}>
  {/* ... */}
  <Combobox.List>
    <Virtualizer
      getGroupKey={(group: ProduceGroup) => group.value}
      renderGroupHeader={(group: ProduceGroup) => <Combobox.GroupLabel>{group.value}</Combobox.GroupLabel>}
    >
      {(item) => <Combobox.Item value={item}>{item.name}</Combobox.Item>}
    </Virtualizer>
  </Combobox.List>
</Combobox.Root>

A group header is a row: it is measured like an item and takes part in the same geometry, so the engine still windows one ordered sequence. Everything public keeps speaking item indexes — activeIndex, scrollToIndex, getItemMetrics, getIndexAtOffset, aria-posinset — and the translation to rows happens in one place.

What makes a virtualized group still a group for assistive technology: each group's mounted rows are wrapped in a role="group" element named by its header through aria-labelledby, and when the header itself has scrolled out of the window it stays mounted, hidden, as the wrapper's first child, so the reference keeps resolving. Inside <Combobox.List> the header is a <Combobox.GroupLabel>, which picks its id up from the virtualizer; <Combobox.Group> is not used, since the virtualizer owns the wrapper. In a list of your own the header renderer receives the id as its third argument.

Two things follow from the header being a row and the collection being filtered per keystroke. estimatedGroupHeaderHeight estimates headers separately, and headers never feed the running average that refines the item estimate. getGroupKey gives groups an identity that survives a preceding group being filtered out; it defaults to the group's index.

The virtualization seam gained one optional field, groups, which a list publishes alongside its flat items; <Combobox.List> and <Autocomplete.List> do. Select can adopt it the same way on its own branch.

Grid mode is still not supported.

Table layout

layout="table" renders the virtualizer as a <tbody> inside a table of your own — the <colgroup>, the sticky <thead>, a <tfoot> and the scroll container around the table all stay yours — and the item renderer returns the <tr> elements themselves, with its third argument spread onto them so they can be measured. activeIndex, scrollToIndex, grouped collections and trailing work as in a list; group headers and trailing content become rows.

<div className="table-scroll">
  <table>
    <colgroup>…</colgroup>
    <thead>…</thead>
    <Virtualizer layout="table" items={rows} getItemKey={(row) => row.id}>
      {(row, index, rowProps) => <tr {...rowProps} aria-rowindex={index + 2}>…</tr>}
    </Virtualizer>
  </table>
</div>

The first version reserved the space of the rows outside the window with an empty row on either side of them, and showed a blank stretch whenever a scroll outran the rendered rows: the compositor moves the scrollport before the main thread commits the next window, and no buffer helps a scrollbar drag. The list layout never shows that because its rows sit in a sticky viewport moved by a transform, so the compositor keeps showing the rows it has. A <tbody> cannot contain that scaffold, but it can be it: the section is now position: sticky and transformed itself, and a second <tbody> after it reserves the space of the rest. Sticky header cells need a z-index above it. This relies on sticky positioning and transforms applying to row groups, which Chrome and Firefox support; Safari is still to be verified.

Docs gained a Tables section with a demo, and there are virtualizer/list and virtualizer/table experiments.

Testing

Virtualizer 254 tests in Chromium and 183 in jsdom, covering windowing, measurement, scroll anchoring, the retained highlight, scrollport padding, paging, grouped collections (wrappers, retained headers, index translation, header estimates, React 17 ids), the table layout, and each of the props above. Combobox 1018 in Chromium, Autocomplete 81, Select 506 for the list-navigation change. Typecheck, lint, stylelint and prettier clean; error codes and generated API docs regenerated.

Much of the behaviour here came from building a real application against the API and reporting what it could not express — the reason totalItems, onEndReached, remeasure(), trailing and the page keys exist at all, rather than being guessed at.

🤖 Generated with Claude Code

@michaldudak michaldudak added the component: combobox Changes related to the combobox component. label Aug 11, 2026
@michaldudak
michaldudak requested a review from atomiks as a code owner August 11, 2026 18:22
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

commit: 59b139f

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+92.9KB(+17.96%) 🔺+28.8KB(+17.17%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · precise to ±7.8% (±14.8% at worst) · ran 3m 57s · details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 97ce477
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6b044c3cdf622b742ef261bb
😎 Deploy Preview https://deploy-preview-5466--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c05506f3ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* Primitive item values use the value itself by default. Required when item values are
* objects.
*/
getItemKey?: ((item: Value) => string | number) | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass the item index to getItemKey

For collections containing the same primitive value or object reference more than once, every occurrence necessarily receives the same ID because getItemKey is given only the item. Consumers cannot disambiguate entries such as items={['A', 'A']}, so production rendering reuses duplicate React and virtualizer row IDs and shares measurement metadata between distinct rows. Include the logical index in this callback, or otherwise provide a supported way to assign unique keys to repeated values.

Useful? React with 👍 / 👎.

@michaldudak
michaldudak force-pushed the virtualizer-standalone branch from f0e1c08 to a873cbc Compare August 11, 2026 18:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a873cbc2d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50a558b393

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 234aec620f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

michaldudak added a commit to michaldudak/base-ui that referenced this pull request Aug 24, 2026
`docs/.../react/utils/list-virtualizer/types.md` survived the rename to
`Virtualizer` with no `page.mdx` beside it. The docs generator still built a
nav entry from it, so the utils index listed the component twice, under both
its old and new name, and the generated index never matched what validation
expected — which is what "Generated files verification" and "Validating Docs"
were failing on.

This is a leftover of the rename in mui#5466 rather than of the merge here, and
belongs on that branch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56bd8fef47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

michaldudak and others added 4 commits August 28, 2026 14:15
Renders only the items in and around the viewport, so a combobox over a large
collection mounts a window of rows instead of all of them. `<Combobox.Virtualizer>`
is the scroll container and the only item-rendering child of `<Combobox.List>`;
each item renderer returns exactly one `<Combobox.Item>`.

Items that are not mounted still take part in the list: keyboard navigation moves
through the whole collection, `isItemDisabled` decides disabled state for items
that were never rendered, and each rendered item carries the collection metadata
assistive technology needs. Heights are estimated until measured, and a static
`estimatedItemHeight` is refined with the running average of the items measured
so far, so the scrollbar settles without scrolling through the list.

Built on `@mui/x-virtualizer` for the windowing engine, with the geometry Base UI
needs on top of it: scroll anchoring across measurement updates, a retained row
for an offscreen highlight, scrollport padding treated the way a plain scrolling
list treats it, and a deferred estimate refresh so a gesture is not interrupted
by a geometry rewrite.

Also carries the API the surrounding app needs to drive it: `totalItems` for a
collection larger than the items given, `onEndReached` for paging, `remeasure()`
for heights taken under a layout that has since changed, a `trailing` slot for
content after the last item, and page keys that move the highlight so a long
list stays reachable from the keyboard without making the scroll container a tab
stop.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Makes the virtualizer a list-agnostic component exported from
`@base-ui/react/list-virtualizer`, rather than a part that only a combobox can
own. `<ListVirtualizer>` binds to the surrounding list through a host published
by that list, so the windowing lives in one component while each list keeps its
own item semantics — it already works inside `<Autocomplete.List>`, and any list
that publishes a host can use it.

The host context deliberately carries no reactive state, so `<Combobox.Item>`
does not re-render on every highlight change; the state the virtualizer windows
against is published separately, and only the virtualizer subscribes to it.

Rendering it outside a list that supports virtualization throws, since there is
no collection to window.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Lets the virtualizer window any list, not only one that publishes a host through
context. Pass the collection to its own `items` prop and it renders on its own;
omit it inside a list that supports virtualization and it binds to that list as
before, so the Combobox integration keeps its ergonomics. It throws only when
neither source provides a collection.

Two decisions the component used to conflate are now separate: where the
collection comes from, and whether a row publishes metadata through a list's
`<Item>` context. Prop-supplied items rendered inside a list still reach a
`<Combobox.Item>`, and items rendered without one receive that metadata as the
third argument of the item renderer, so a standalone list stays accessible.

`activeIndex` carries the scroll decision with it — an index alone scrolls the
item into view, `{ index, scroll: false }` leaves the viewport alone for a
highlight following the pointer, and `align` says where a scrolled item lands.
Keeping them in one value is what stops the scroll intent drifting from the
index it belongs to.

Renamed from `ListVirtualizer` to `Virtualizer`, and the entry point from
`@base-ui/react/list-virtualizer` to `@base-ui/react/virtualizer`: the component
windows a flat collection, which a list is only one source of.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@michaldudak
michaldudak force-pushed the virtualizer-standalone branch from 56bd8fe to baa7e7a Compare August 28, 2026 12:23
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 28, 2026
Renaming the component moved its docs page and types source, but the generated
`types.md` beside them stayed, and the utils index kept a "List Virtualizer"
entry linking to a page that no longer exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@michaldudak michaldudak changed the title [Virtualizer] Standalone prop-based API [Virtualizer] Render only the visible items of a large list Aug 28, 2026
# Conflicts:
#	packages/react/src/combobox/group-label/ComboboxGroupLabel.tsx
#	packages/react/src/combobox/group/ComboboxGroup.tsx
#	packages/react/src/combobox/root/AriaCombobox.tsx
#	pnpm-lock.yaml
…e API

Master now requires top-level `import type` and passes the floating root
store to `useListNavigation`. Apply both to code that only exists on this
branch.
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 29, 2026
…rolling

Since master moved to vitest 5, a pointer an earlier test file leaves resting
over the popup or the scroller survives into the next file. The Combobox
alignment test and the laid-out table tests then fail whenever they run after
another virtualizer file, though each passes alone.
Every host created its own item and group contexts, registered its item part by hand for a development check, and cleared four contexts at its root so a list nested in another list's row would not read that row. The virtualizer now owns one item channel and one group-header channel. A host publishes through VirtualizerHostProvider, which also clears both channels for its subtree, its item part calls useVirtualizerItem, which registers it and counts static items, and its group label calls useVirtualizerGroupHeader. virtualItemContext, virtualGroupContext, registerItem, nonVirtualItemCount and the raw host contexts leave the public contract; rendersItemPart declares that rows render the host's item part.
…ublic parts

Covers what the shared channels have to guarantee: a list nested in a row reads none of the row's metadata, a static item part warns whether it mounts before or after the virtualizer, and the one-item-part check runs for a host that declares rendersItemPart and not for one whose rows are plain elements.
…eVirtualizerItem

The hosting section showed a host creating its own item context, nesting the two raw contexts, and clearing both around parts rendered elsewhere. It now shows the provider, the item and group-header hooks, and what rendersItemPart turns on. The API reference is regenerated.
The binding registered a forwarding copy of the handle, with an enabled flag it worked out itself: a table with no scroll container to window against rendered every row while telling its host the virtualizer owned the scroll position, so the host left an activation to a virtualizer that could not scroll to it. The Virtualizer now registers its own handle, carrying the mode it is actually in, through useVirtualizerRegistration, and gates the host's scroll requests on that same mode. The registry gains onVirtualizerChange and the handle getScrollElement, for a host that needs the registration while rendering or the element that scrolls.
The flag was deprecated in a contract that has not shipped: it described the host rather than the activation, so flipping it back without moving the index scrolled to wherever the pointer last rested. Combobox now publishes its highlight as { index, scroll }, and a bare index is an activation that scrolls, for a host as for the activeIndex prop.
…ore releasing the list

The host contract required clearing the suspension while the virtualizer was still mounted. Releasing the list first breaks nothing: a virtualizer unmounted while suspended measures afresh when it mounts again, and one still mounted sees the transition in either order. With Combobox's release order reversed the whole suite passes, including a new test for a closed list opened after a rendered-label autofill pass, so the rule leaves the contract and Combobox's comments stop calling the order load-bearing.
…ListBinding

The binding held the rows the virtualizer renders for a host, the diagnostics a host's item part runs, and the source resolution the Virtualizer asks it for. Each now has a module of its own, and useListBinding is left resolving the collection and the activation.
…ox selection

The click can return before the frame in which ResizeObserver measures the
mounted rows and corrects the estimated placement, so the test sometimes read
the pre-correction position (off by one pixel per row above the selection).
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 30, 2026
…test rewrites the rows

The distant-selection test shrinks the rows after the popup opens and expects the selection to
keep its alignment. That holds while the restoration still re-aligns the selection, which it does
until the adaptive estimate refines one idle window after the last measurement. On a slow machine
the click and the frames the test waits for take longer than that window, the restoration settles
first, and anchoring then holds the topmost visible row, so the selection drifted by the 31 rows
mounted above it (reproduced deterministically with 4x CPU throttling). Hold the idle timers until
the rewrite has landed, then release them and check the alignment again once the restoration
settles.
# Conflicts:
#	pnpm-lock.yaml
…stants

Master now documents metadata from namespace exports, so the Virtualizer's
enums dropped out of the generated API reference after the merge.
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Sep 30, 2026
…ht ledger

Folds the changes from mui#5757 into this branch as one commit. The windowing
engine is rebuilt around viewportController, rowHeightLedger and
windowPlacement, replacing useAdaptiveEstimate, usePendingScroll and
useScrollAnchor. Installs @mui/x-virtualizer from the mui/mui-x#23687
preview, which needs blockExoticSubdeps relaxed until a release includes it.
# Conflicts:
#	docs/src/error-codes.json
#	packages/react/src/combobox/root/AriaCombobox.tsx
#	packages/react/src/floating-ui-react/hooks/useListNavigation.ts
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 2, 2026
# Conflicts:
#	docs/src/app/(docs)/react/components/autocomplete/types.md
#	docs/src/app/(docs)/react/components/combobox/demos/virtualized/css-modules/index.tsx
#	docs/src/app/(docs)/react/components/combobox/demos/virtualized/tailwind/index.tsx
#	docs/src/app/(docs)/react/components/combobox/page.mdx
#	docs/src/app/(docs)/react/components/combobox/types.md
#	packages/react/src/combobox/item/ComboboxItem.tsx
#	packages/react/src/combobox/list/ComboboxList.tsx
#	packages/react/src/combobox/root/AriaCombobox.tsx
#	packages/react/src/combobox/store.ts
#	packages/react/src/utils/popups/interactions/useListNavigation.ts
#	packages/react/test/index.ts
#	pnpm-lock.yaml
#	pnpm-workspace.yaml
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 30, 2026
Replace the root's isItemDisabled prop with a getDisabled accessor on Combobox.createItems(), matching Listbox. The collection answers for items that are not rendered, so keyboard navigation and rendered items read their disabled state from it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. component: virtualizer poc PR: out-of-date The pull request has merge conflicts and can't be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants