Skip to content

Conversation

@kapantzak
Copy link
Contributor

@kapantzak kapantzak commented Jan 31, 2025

When we pass a value to dataColumns prop of the Table component, that changes over re-renders, BodyHeader component cannot distinguish between different versions of table object and keeps the first version of it.

By adding timestamp prop to table object each time we create it, we ensure that memo recognizes each version and re-renders BodyHeader component to reflect latest state.

@kapantzak kapantzak self-assigned this Jan 31, 2025
@github-actions
Copy link

github-actions bot commented Jan 31, 2025

Coverage report

Caution

An unexpected error occurred. For more details, check console

Error: The process '/usr/bin/git' failed with exit code 128
St.
Category Percentage Covered / Total
🔴 Statements 7.91% 224/2831
🔴 Branches 9.4% 201/2138
🔴 Functions 5.69% 59/1036
🔴 Lines 7.99% 201/2516

Report generated by 🧪jest coverage report action from ac1697e

@kapantzak kapantzak requested a review from novykh January 31, 2025 15:36
@kapantzak kapantzak marked this pull request as ready for review January 31, 2025 15:36
Copy link
Member

@novykh novykh left a comment

Choose a reason for hiding this comment

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

This has a number of performance issues. Better to update the selector on the component you want to rerender when columns change.
I think you need this:

columnsCount: state.table && state.table.getAllColumns().length,

But again I would proceed with caution and checking the performance implications - especially on tables that do not need this check.

@kapantzak kapantzak force-pushed the fix-memoized-table-object branch from 042711e to c6c8372 Compare February 3, 2025 07:56
@kapantzak kapantzak requested a review from novykh February 3, 2025 08:02
Copy link
Member

@novykh novykh left a comment

Choose a reason for hiding this comment

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

Check the comments but for me it's good to go.

grouping: state.grouping,
columnsCount: state.table && state.table.getAllColumns().length,
columnsCount: columns.length,
columnsFilters: columns.map(({ columnDef }) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be an object with filterOptions key? Why not just return the columnDef?.meta?.filter?.options? It will be easier for the diff checker to run shallower by one level :)

import Cell from "./cell"

const rerenderSelector = state => {
const columns = state.table?.getAllColumns() || []
Copy link
Member

Choose a reason for hiding this comment

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

should this become state.table?.getAllColumns?.()?

@kapantzak kapantzak merged commit f274e7b into master Feb 3, 2025
1 check passed
@kapantzak kapantzak deleted the fix-memoized-table-object branch February 3, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants