diff --git a/packages/table-core/src/core/rows/constructRow.ts b/packages/table-core/src/core/rows/constructRow.ts index 9fecbb23ed..5ec6eb7610 100644 --- a/packages/table-core/src/core/rows/constructRow.ts +++ b/packages/table-core/src/core/rows/constructRow.ts @@ -51,6 +51,7 @@ export const constructRow = < row._displayIndexCache = -1 row._uniqueValuesCache = makeObjectMap() row._valuesCache = makeObjectMap() + row._accessorFnsCache = makeObjectMap() row.depth = depth row.id = id row.index = rowIndex diff --git a/packages/table-core/src/core/rows/coreRowsFeature.types.ts b/packages/table-core/src/core/rows/coreRowsFeature.types.ts index 8a38bed8c9..1a9b663f59 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.types.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.types.ts @@ -25,6 +25,7 @@ export interface Row_CoreProperties< _displayIndexCache: number _uniqueValuesCache: Record _valuesCache: Record + _accessorFnsCache: Record /** * The depth of the row (if nested or grouped) relative to the root row array. */ diff --git a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts index f37ce79828..ff95d2ac3c 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts @@ -79,16 +79,21 @@ export function row_getValue< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, columnId: string) { - if (hasOwn(row._valuesCache, columnId)) { + const column = row.table.getColumn(columnId) + + if ( + hasOwn(row._valuesCache, columnId) && + hasOwn(row._accessorFnsCache, columnId) && + row._accessorFnsCache[columnId] === column?.accessorFn + ) { return row._valuesCache[columnId] } - const column = row.table.getColumn(columnId) - if (!column?.accessorFn) { return undefined } + row._accessorFnsCache[columnId] = column.accessorFn row._valuesCache[columnId] = column.accessorFn(row.original, row.index) return row._valuesCache[columnId] @@ -109,12 +114,16 @@ export function row_getUniqueValues< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, columnId: string) { - if (hasOwn(row._uniqueValuesCache, columnId)) { + const column = row.table.getColumn(columnId) + + if ( + hasOwn(row._uniqueValuesCache, columnId) && + hasOwn(row._accessorFnsCache, columnId) && + row._accessorFnsCache[columnId] === column?.accessorFn + ) { return row._uniqueValuesCache[columnId] } - const column = row.table.getColumn(columnId) - if (!column?.accessorFn) { return undefined } @@ -124,6 +133,7 @@ export function row_getUniqueValues< return row._uniqueValuesCache[columnId] } + row._accessorFnsCache[columnId] = column.accessorFn row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues( row.original, row.index,