Table rows are re-rendered when datasource is strictly equal
See original GitHub issueVersion
2.9.1
Environment
osx 10.10.5 with Chrome 57
Reproduction link
https://codepen.io/foxxmd/pen/GmqojV
Steps to reproduce
- Create a
<Table/>
inside a Component<X>
that receives- a prop for the table
dataSource
(ex,list
) - props not for table
- a prop for the table
- Update any props for
<X>
that are notlist
To see what is re-rendered using the provided codepen open the browser console and click “Run” again.
What is expected?
Since this.props.list === nextProps.list
I would expect that <Table>
would not re-render any <TableRow>
or <TableCell>
components
What is actually happening?
All <TableRow>
and <TableCell>
components are re-rendered.
After reading (google translating) these issues
- https://github.com/ant-design/ant-design/issues/2884
- https://github.com/ant-design/ant-design/issues/2029#issuecomment-233841928
- https://github.com/ant-design/ant-design/issues/2484#issuecomment-234860010
- https://github.com/react-component/table/pull/96
I was under the impression the re-render was due to custom render
functions in the columns
properties but the reproduced codepen verifies that the re-render occurs regardless.
This causes a huge performance hit even when not interacting with the table since the table re-renders any time props are updated. These are the performance metrics for a 40 row, 6 column table in my app.
Additionally adding rowSelection
to the <Table>
causes all checkboxes to have DOM operations performed on them. I’m not sure if this is related to the re-renders specifically but its also a huge performance hit.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
I did a few things because I found even more props on
Table
were causing the whole component to re-render when I didn’t need it to:Table
andTitle
component ofTable
Title
component is updated separately fromTable
because my scenario has components inTitle
re-rendering based on row selection but this didn’t require re-rendering every row inTable
(since data was the same)Additionally, when using
PureTable
, I usecreateSelector
from reselect to provide data to thecolumns
prop because it was also causing a re-render of the whole table even when the data was equal (but not the exact same object)No problem thanks for the response. Yeah I ended up using
onlyUpdateForKeys
fromrecompose
and wrapping the table. Good to know about the checkbox bug,