Repository navigation
Description
Provide a general summary of the issue here
When a collection is virtualized with <Virtualizer> (e.g. a virtualized Table), the Virtualizer publishes a CollectionRendererContext ({ isVirtualized: true, CollectionRoot, layout, dropTargetDelegate }) that wraps its entire React subtree. Any other collection component (Menu, ListBox, Select, …) rendered inside an overlay (Popover / Dialog) that is a React descendant of the virtualized collection inherits that context — React context propagates through portals — and renders its own collection with the ancestor's CollectionRoot / layout.
If the ancestor layout is a TableLayout (virtualized Table), the nested overlay collection (a Menu/ListBox collection, which has no columns) is laid out with TableLayout, and TableLayout.buildCollection() throws:
TypeError: collection.columns is not iterable
In practice: a virtualized Table whose column headers contain menus/selects/filter popovers crashes the whole table (via the error boundary) the moment any of those popovers is opened.
🤔 Expected Behavior?
Overlay content (Popover / Dialog / Modal) should not inherit a virtualized ancestor's CollectionRendererContext. A Menu / ListBox / Select opened from inside a virtualized Table (or any virtualized collection) should render its own collection with the default renderer (or with its own Virtualizer if one is explicitly nested), not with the ancestor collection's layout. Opening the popover should just work.
😯 Current Behavior
Opening the overlay throws and unmounts the tree:
TypeError: collection.columns is not iterable
at TableLayout.buildCollection (TableLayout.ts:169:35)
at TableLayout.update (ListLayout.ts:359:27) // super.update
at TableLayout.update (TableLayout.ts:162:11)
at Virtualizer.relayout (Virtualizer.ts:194:17)
at Virtualizer.render (Virtualizer.ts:419:12)
at useVirtualizerState (useVirtualizerState.ts:91:34)
at CollectionRoot (Virtualizer.tsx:108:15)
Root cause chain:
Virtualizer(Virtualizer.tsx) providesCollectionRendererContextwith{ isVirtualized: true, CollectionRoot, layout, dropTargetDelegate }around its children.Menu(Menu.tsx,let { isVirtualized, CollectionRoot } = useContext(CollectionRendererContext)) andListBox(ListBox.tsx, readsisVirtualized/CollectionRoot/layoutDelegatefrom the same context) render their collection through the inheritedCollectionRoot. Neither resets the context, andPopover/Dialogdo not reset it either.- Because the popover content is still a React descendant of the
Virtualizer(portals preserve React context), the menu/listbox is laid out with the ancestor'sTableLayout. TableLayout.buildCollection()doesfor (let column of collection.columns), but the overlay's collection is aMenu/ListBoxcollection (not aTableCollection), socollection.columnsisundefined→ not iterable.
Note: a real (even empty) TableCollection always exposes columns (columns: GridNode<T>[] = []), so this only happens because a non-table collection reaches the table layout.
💁 Possible Solution
The overlay boundary should reset the collection renderer so nested collections don't inherit an unrelated virtualized ancestor's renderer. Options:
- Have
Popover/Dialog/Modal(or the overlayProviderinside them) resetCollectionRendererContexttoDefaultCollectionRendererfor their children, or - Have
MenuTrigger/Select/ComboBoxreset it around thePopover+ListBox/Menuthey render.
Consumer-side workaround (works today, since both symbols are publicly exported from react-aria-components):
import { CollectionRendererContext, DefaultCollectionRenderer } from 'react-aria-components'
<Popover>
<CollectionRendererContext.Provider value={DefaultCollectionRenderer}>
{/* Menu / ListBox / Select content */}
</CollectionRendererContext.Provider>
</Popover>This is a no-op outside a virtualizer (the context is already DefaultCollectionRenderer), and a nested explicit <Virtualizer> inside the popover still overrides it, so no legitimate case is broken.
🔦 Context
We virtualize a data grid built on Table using Virtualizer + a custom TableLayout subclass. Column header cells contain menus (sort/reorder/resize actions), a column-select menu, and filter popovers. After migrating the grid to Virtualizer, opening any header popover crashes the entire grid through the error boundary — it makes header menus/selects/filters unusable in a virtualized table. This is a trading application where the grid is central, so the whole feature is blocked without the workaround above.
🖥️ Steps to Reproduce
Minimal reproduction (a virtualized Table whose column header contains a MenuTrigger → Popover → Menu):
import {
Virtualizer,
TableLayout,
Table,
TableHeader,
TableBody,
Column,
Row,
Cell,
MenuTrigger,
Button,
Popover,
Menu,
MenuItem,
} from 'react-aria-components'
function Example() {
return (
<div style={{ height: 200 }}>
<Virtualizer layout={TableLayout} layoutOptions={{ rowHeight: 32 }}>
<Table aria-label="Example">
<TableHeader>
<Column isRowHeader>
Name
<MenuTrigger>
<Button aria-label="Menu">☰</Button>
<Popover>
<Menu>
<MenuItem>Sort ascending</MenuItem>
<MenuItem>Sort descending</MenuItem>
</Menu>
</Popover>
</MenuTrigger>
</Column>
</TableHeader>
<TableBody>
<Row>
<Cell>Alpha</Cell>
</Row>
<Row>
<Cell>Bravo</Cell>
</Row>
</TableBody>
</Table>
</Virtualizer>
</div>
)
}Steps:
- Render the virtualized table above — it renders fine.
- Click the
☰menu button in the column header to open thePopover+Menu. - The app throws
TypeError: collection.columns is not iterableand the tree unmounts (error boundary).
The same crash occurs with Select/ComboBox/ListBox inside a Popover in the header, and generally with any Menu/ListBox/Select rendered in an overlay under a virtualized Table.
(A live StackBlitz/CodeSandbox based on the snippet above can be added.)
Version
1.20.0
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
MacOS
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
Activity
LFDanLu commentedon Aug 26, 2026
The above reproduction code seems to work in https://stackblitz.com/edit/5mdlxu8i?file=src%2FExample.tsx, do you have a repo or something you can share?
coolassassin commentedon Aug 27, 2026
@LFDanLu Sure:
https://stackblitz.com/edit/5mdlxu8i-avw9sqcq?file=src%2Findex.tsx
LFDanLu commentedon Aug 27, 2026
thanks for the repo, is there a particular use case as to why the MenuTrigger is being rendered inside the Virtualizer as a sibling of the Table? I saw the comment saying:
but can't you just move it outside the Virtualizer since the Virtualizer is meant to apply specifically to a single wrapped collection component? We could certainly clear the context defensively but the Virtualizer was always meant to specifically closely wrap a single collection component IIRC
coolassassin commentedon Aug 27, 2026
@LFDanLu Sorry for the noise — my original repro was slightly mis-targeted. Wrapping
MenuTriggerdirectly inside<Column>doesn't reproduce because<Column>and<Cell>already resetCollectionRendererContextback toDefaultCollectionRendereraround their ownchildren(that's been there since #6640, it's not a recent fix). That's why your Stackblitz worked fine.The leak is still there though — it just isn't gated on
<Column>/<Cell>at all. Any overlay-triggering element that's a React descendant of<Virtualizer>but not wrapped by<Column>/<Cell>still inherits the ancestor'sisVirtualized/CollectionRoot/layout. A toolbar button placed next to the table (customize columns, global filter, bulk row actions — all pretty ordinary patterns) is enough:Clicking the menu button crashes the whole tree, verified against
react-aria-components@1.20.0in a real browser:(It reproduces even more minimally without
<Table>at all — just<Virtualizer layout={TableLayout}><MenuTrigger>…</MenuTrigger></Virtualizer>.)Which brings me to the actual point I want to raise: I don't think resetting the context at
<Column>/<Cell>is the right place to fix this, even as a stopgap. It only protects consumers who go through RAC's own<Column>/<Cell>components. Anyone building a custom grid/table on top of the lower-levelreact-ariahooks (useGridCell,useTableCell, etc. — which is exactly what we do for keyboard-navigation/focus reasons) reimplements the column/cell wrapper themselves and never gets that reset, so the leak is still fully live for us regardless of RAC version. Effectively the fix is invisible unless you happen to render your table cells through RAC's own components verbatim.It seems like the more robust place to reset
CollectionRendererContextis wherever a new collection actually gets created — i.e. inside the components that calluseContext(CollectionRendererContext)to render themselves as a root collection:Menu,ListBox,GridList,Tree,Select,ComboBox/Autocomplete,TagGroup,Tabs, etc. Since each of these is itself a distinct collection consumer, they're the ones that should decide whether they're virtualized (only if there's a<Virtualizer>that's actually theirs, not an ancestor's), rather than relying on some outer container (Column/Cell/whatever a consumer's own DOM/JSX structure happens to be) to have pre-reset the context for them. That would fix the leak structurally for any consumer — RAC's own<Table>, our custom wrapper, or anyone else's — instead of patching it ad hoc at every place a collection might be rendered inside a virtualized ancestor.There's arguably an even more general boundary worth considering:
Popover(and overlay/portal machinery in general -Dialog,Modal,Tooltip) could resetCollectionRendererContextback toDefaultCollectionRendererby default for their content. An overlay is conceptually detached from its DOM ancestor even though React context still flows through the portal - a virtualized layout from the trigger's ancestor tree essentially never makes sense for content rendered inside a popover/dialog/modal. Resetting there would close off this whole class of bugs by default, independent of whichever collection component happens to be rendered inside (including ones RAC doesn't know about, or nested overlays). It could complement (not replace) resetting at the collection-creating components mentioned above - the two together would make this basically impossible to hit by accident.Happy to help test if either direction is worth pursuing.
LFDanLu commentedon Aug 27, 2026
I see, I think the latter suggestion of clearing at overlay boundary makes sense, would you like to prototype that? That being said, just to clarify your own use case: are you using RAC components alongside your own react-aria hook built components? I assume so since you are using the Virtualizer but using the hooks to build custom grids/tables?
snowystinger commentedon Aug 27, 2026
If we can avoid pulling Contexts into unrelated components we should, it makes initial bundle size larger and can increase overall bundle size for others
su-jin1425 commentedon Aug 28, 2026
Hi, I’m interested in working on this issue. I saw the discussion about prototyping the overlay-boundary approach, so I wanted to check whether anyone is currently working on it or planning to open a PR. If it’s available, I’d be happy to investigate it.
coolassassin commentedon Aug 31, 2026
@LFDanLu
Unfortunately, I don't have resources to make a prototype in short term perspective. Maybe later
Answering to your second question, yes, we use combination of RAC component and our own components, because we need a bit more flexibility (#10121) and performance in some cases (#10088, #10477, #10490)
But, we would like to use out of box solution
LFDanLu commentedon Aug 31, 2026
@su-jin1425 feel free to pick this up!
su-jin1425 commentedon Aug 31, 2026
Great i will work on it.
fix(react-aria-components): prevent Virtualizer context leak into ove…
fix(react-aria-components): prevent Virtualizer context leak into ove…
su-jin1425 commentedon Sep 1, 2026
Hi @LFDanLu I’ve completed the fix for #10500 and pushed the final changes to PR #10544. The overlay-boundary approach is implemented, the regression tests are passing, and all CI checks are now green. The final diff is limited to the necessary changes.
fix(react-aria-components): prevent virtualizer CollectionRendererCon…
test(react-aria-components): add regression test for Virtualizer cont…
test(react-aria-components): add regression test for Virtualizer cont…
snowystinger commentedon Sep 3, 2026
Thanks for the Issue, after explorations in @su-jin1425 's PR this is the expected behaviour. We cannot know what collection a particular virtualizer context is meant for. We actually rely on the context going through overlays right now, which means others may be relying on this as well if they copied our work as a starting point.
react-spectrum/packages/@react-spectrum/s2/src/Picker.tsx
Line 457 in 70ee052
What you could do though is wrap the Virtualizer and create your own forwarding context and immediately clear the current conext. Then wrap each of the collection components to consume that and re-start the Virtualizer context there. You can use whatever method of targeting you want. A specific context to each component, something akin to our slots architecture, etc.
I'm going to close this issue.