petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.13k stars 299 forks source link

[BUG] `TableBody` in components props of `TableVirtuoso` causes rendering issue #1052

Closed Gumichocopengin8 closed 5 months ago

Gumichocopengin8 commented 5 months ago

Describe the bug

When TableBody in components props of TableVirtuoso is defined, TableVirtuoso does not render data properly.

Reproduction Use https://codesandbox.io/ to illustrate the problem so that I can observe the issue on my side and make sure that a potential fix reliably addresses it.

Code Link

Minimum code to reproduce the bug

import { TableVirtuoso } from 'react-virtuoso';

export default function App() {
  return (
    <div>
      <TableVirtuoso
        style={{ height: 400 }}
        components={{
          TableBody: (props) => <tbody {...props} />, // comment out or uncomment this line to see the rendering bug
        }}
        data={Array.from({ length: 1000000 }).map((_, i) => ({
          name: `name ${i}`,
        }))}
        fixedHeaderContent={() => (
          <>
            <th style={{ backgroundColor: 'white' }}>Name</th>
          </>
        )}
        itemContent={(_index, user) => (
          <>
            <td>{user.name}</td>
          </>
        )}
      />
    </div>
  );
}

To Reproduce Steps to reproduce the behavior:

  1. First comment out TableBody: (props) => <tbody {...props} /> line to see the expected behavior
  2. Uncomment the line and refresh page, then table only renders 1 row even though there are more than 1 data

Expected behavior It should show all data with TableBody in components prop.

Screenshots

Unexpected

image

Expected

image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

petyosi commented 5 months ago

You need to forward the ref to the element. See the material UI table example.