@@ -1425,18 +1425,23 @@ export function useDeleteColumn({ workspaceId, tableId }: RowMutationContext) {
14251425
14261426 const lower = columnName . toLowerCase ( )
14271427 const previousDetail = queryClient . getQueryData < TableDefinition > ( tableKeys . detail ( tableId ) )
1428+ // The grid deletes by stable id; legacy callers may pass a name. Resolve
1429+ // the column's storage id once from either form, then strip schema,
1430+ // widths, and row data by that single id — all three are id-keyed, so a
1431+ // name arg with a distinct id must never be used as the strip key directly.
1432+ const target = previousDetail ?. schema . columns . find (
1433+ ( c ) => getColumnId ( c ) === columnName || c . name . toLowerCase ( ) === lower
1434+ )
1435+ const stripKey = target ? getColumnId ( target ) : columnName
1436+
14281437 if ( previousDetail ) {
1429- // The grid deletes by stable id; legacy callers may pass a name. Match
1430- // on either so the column is dropped from the optimistic schema cache.
1431- const nextColumns = previousDetail . schema . columns . filter (
1432- ( c ) => getColumnId ( c ) !== columnName && c . name . toLowerCase ( ) !== lower
1433- )
1438+ const nextColumns = previousDetail . schema . columns . filter ( ( c ) => getColumnId ( c ) !== stripKey )
14341439 const prevWidths = previousDetail . metadata ?. columnWidths
14351440 const nextMetadata = prevWidths
14361441 ? {
14371442 ...previousDetail . metadata ,
14381443 columnWidths : Object . fromEntries (
1439- Object . entries ( prevWidths ) . filter ( ( [ k ] ) => k . toLowerCase ( ) !== lower )
1444+ Object . entries ( prevWidths ) . filter ( ( [ k ] ) => k !== stripKey )
14401445 ) ,
14411446 }
14421447 : previousDetail . metadata
@@ -1448,9 +1453,8 @@ export function useDeleteColumn({ workspaceId, tableId }: RowMutationContext) {
14481453 }
14491454
14501455 const rowSnapshots = await snapshotAndMutateRows ( queryClient , tableId , ( row ) => {
1451- const matchKey = Object . keys ( row . data ) . find ( ( k ) => k . toLowerCase ( ) === lower )
1452- if ( ! matchKey ) return null
1453- const { [ matchKey ] : _removed , ...rest } = row . data
1456+ if ( ! ( stripKey in row . data ) ) return null
1457+ const { [ stripKey ] : _removed , ...rest } = row . data
14541458 return { ...row , data : rest }
14551459 } )
14561460
0 commit comments