react-spectrum: Table component randomly fails to render provided items.
Provide a general summary of the issue here
I’m using Table component in my Remix js application. Table items are provided by the loader function. Table sorting, search, pagination is handled with the URL query parameters. When user interacting with the table sorting, pagination or search for some time, the table component randomly stop showing content and renders empty state fallback component instead. I checked the items array, it contains data, but when I use React dev tools and check TableBody component, it shows that collection is empty, while props have items.
Here is my code
<Table onSortChange={handleSorting} sortDescriptor={getSortDescriptor()}>
<TableHeader columns={columns}>
{(column) => (
<Column isRowHeader={column.isRowHeader}>{column.name}</Column>
)}
</TableHeader>
<TableBody items={tableRows} renderEmptyState={() => "no results"}>
{(item) => (
<Row aria-label="Table Row" columns={customerTableColumns}>
{(column) => (
<Cell aria-label="Table Cell">{item[column.id]}</Cell>
)}
</Row>
)}
</TableBody>
</Table>
🤔 Expected Behavior?
Table should render items if provided.
😯 Current Behavior
Sometimes table does not render items.
💁 Possible Solution
Unfortunately I don’t have solution.
🔦 Context
Items are dynamic, provided by the Remix loader with the help of useLoaderData hook.
🖥️ Steps to Reproduce
Unable to reproduce it in sandbox. Might be SSR related.
Version
1.1.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
Remix js
What operating system are you using?
Mac OS
🧢 Your Company/Team
Arbonics
🕷 Tracking Issue
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 19 (8 by maintainers)
I’m having the same issue. Combination with react-aria table and react-query. Rows are correctly added to table initially, but the table removes all rows after click on one of the rows or sortable header… Stumped why this is happening since using a simple html table works fine.
@snowystinger @AndrewLeedham
FYI, I discovered that using an array index as the item ID, instead of a unique identifier like UUID4, prevents the issue. It seems that during sorting and searching, the IDs of the rows change, whereas the index remains constant. This can serve as a temporary workaround for now.
I can no longer reproduce with @joshuajaco’s reproduction on the latest nightly version. Going to close this as fixed by #7912.
Sharing my findings here.
Background for those not familiar with RAC architecture (like myself):
collection.addNodefollowed bycollection.commitcall.Document.updateCollection.Document.updateCollectionis called byDocument.updateCollectionand byuseSSRCollectionNodewhich might be the key to this, because it makes the last successful call that updates the collection.Findings:
Document.updateCollectionis called several times, which updates the collection as described above.Document, I can see a long series ofthis.mutatedNodes.addcalls, followed byTableCollection.addNodecall, as if the collection was being re-created from scratch for some reason. After this long series of calls though,Document.updateCollectionnever gets called byuseSSRCollectionNodeagain (!), so the collection is never updated with all the added rows! So the next time the component renders, collection has a size of 0.Document.addNodeimplementation:Document.updateCollectiondoes not get called OR that the collection is being needlessly re-created after first render (and it shouldn’t need yet anotherDocument.updateCollectionin the first place). It might go deeper than that, I ran out of time.Ready-to-use patch: @react-aria-collections-npm-3.0.0-alpha.3-04c359b98f.patch
We are having a similar issue in our next.js app.
I was able to deterministically reproduce it using a combination of the following:
The full reproduction is at https://github.com/joshuajaco/react-aria-table-nextjs-bug
We’re seeing a similar problem as well where the rows/table content disappears if a user rapidly tries to load the table (eg. switching between the column sorts or paginating the table) with dynamic content. The
CollectionBranchcomponent seems to contain the props/components needed to render the rows/items but does not render any of the items