File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -248,6 +248,26 @@ export function useTableRows({
248248 } )
249249}
250250
251+ /** Merges a freshly-fetched page into the cached page while preserving row
252+ * object identity for unchanged rows (by `updatedAt`). Returns the original
253+ * `prev` reference unchanged when nothing has actually changed — callers can
254+ * use a `===` check to skip a `setQueryData` write entirely. */
255+ function mergePagePreservingIdentity (
256+ prev : TableRowsResponse ,
257+ fresh : TableRowsResponse
258+ ) : TableRowsResponse {
259+ if ( prev . totalCount !== fresh . totalCount || prev . rows . length !== fresh . rows . length ) return fresh
260+ const prevById = new Map ( prev . rows . map ( ( r ) => [ r . id , r ] ) )
261+ let allSame = true
262+ const nextRows = fresh . rows . map ( ( freshRow ) => {
263+ const prevRow = prevById . get ( freshRow . id )
264+ if ( prevRow && String ( prevRow . updatedAt ) === String ( freshRow . updatedAt ) ) return prevRow
265+ allSame = false
266+ return freshRow
267+ } )
268+ return allSame ? prev : { ...fresh , rows : nextRows }
269+ }
270+
251271export function tableRowsParamsKey ( {
252272 pageSize,
253273 filter,
You can’t perform that action at this time.
0 commit comments