️ prevent SitetableCell from rerendering unnecessarily

This commit is contained in:
Fred KISSIE
2026-05-11 19:27:00 +02:00
parent ab494521b1
commit 3855486a00

View File

@@ -45,6 +45,7 @@ import { usePathname, useRouter } from "next/navigation";
import { import {
startTransition, startTransition,
useEffect, useEffect,
useMemo,
useOptimistic, useOptimistic,
useState, useState,
useTransition useTransition
@@ -180,7 +181,8 @@ export default function SitesTable({
}); });
} }
const columns: ExtendedColumnDef<SiteRow>[] = [ const columns = useMemo<ExtendedColumnDef<SiteRow>[]>(() => {
const cols: ExtendedColumnDef<SiteRow>[] = [
{ {
accessorKey: "name", accessorKey: "name",
enableHiding: false, enableHiding: false,
@@ -470,26 +472,6 @@ export default function SitesTable({
); );
} }
}, },
...(isLabelFeatureEnabled
? [
{
accessorKey: "labels",
header: () => (
<span className="p-3 text-end w-full inline-block">
{t("labels")}
</span>
),
cell: ({ row }: { row: { original: SiteRow } }) => {
return (
<SiteLabelCell
site={row.original}
orgId={orgId}
/>
);
}
}
]
: []),
{ {
id: "actions", id: "actions",
enableHiding: false, enableHiding: false,
@@ -546,6 +528,23 @@ export default function SitesTable({
} }
]; ];
if (isLabelFeatureEnabled) {
cols.splice(cols.length - 1, 0, {
accessorKey: "labels",
header: () => (
<span className="p-3 text-end w-full inline-block">
{t("labels")}
</span>
),
cell: ({ row }: { row: { original: SiteRow } }) => (
<SiteLabelCell site={row.original} orgId={orgId} />
)
});
}
return cols;
}, [isLabelFeatureEnabled, orgId, t, searchParams]);
function toggleSort(column: string) { function toggleSort(column: string) {
const newSearch = getNextSortOrder(column, searchParams); const newSearch = getNextSortOrder(column, searchParams);