From c23ff58e1340df85bea6f815a50e886717a40657 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sun, 28 Sep 2025 01:33:38 +0800 Subject: [PATCH] perf: uninstall classnames, install clsx --- docs/examples/animation.tsx | 4 ++-- docs/examples/virtual-list-grid.tsx | 4 ++-- docs/examples/virtual-list.tsx | 4 ++-- package.json | 2 +- src/Body/BodyRow.tsx | 12 +++++------- src/Body/index.tsx | 4 ++-- src/Cell/index.tsx | 4 ++-- src/FixedHolder/index.tsx | 4 ++-- src/Header/Header.tsx | 6 +++--- src/Table.tsx | 18 +++++++----------- src/VirtualTable/BodyLine.tsx | 10 ++++------ src/VirtualTable/VirtualCell.tsx | 4 ++-- src/VirtualTable/index.tsx | 9 +++------ src/hooks/useRowInfo.tsx | 4 ++-- src/stickyScrollBar.tsx | 4 ++-- src/utils/expandUtil.tsx | 6 +++--- 16 files changed, 44 insertions(+), 55 deletions(-) diff --git a/docs/examples/animation.tsx b/docs/examples/animation.tsx index d0105495e..d5c070530 100644 --- a/docs/examples/animation.tsx +++ b/docs/examples/animation.tsx @@ -1,6 +1,6 @@ import React from 'react'; import CSSMotionList from 'rc-animate/lib/CSSMotionList'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import toArray from '@rc-component/util/lib/Children/toArray'; import type { TableProps } from 'rc-table'; import Table from 'rc-table'; @@ -27,7 +27,7 @@ const MotionBody: React.FC = ({ children, ...props }) => { {({ key, className }) => { const node = nodesRef.current[key]; return React.cloneElement(node, { - className: classNames(node.props.className, className), + className: clsx(node.props.className, className), }); }} diff --git a/docs/examples/virtual-list-grid.tsx b/docs/examples/virtual-list-grid.tsx index aee4e6d4d..30caca3c0 100644 --- a/docs/examples/virtual-list-grid.tsx +++ b/docs/examples/virtual-list-grid.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import { VariableSizeGrid as Grid } from 'react-window'; import Table from 'rc-table'; import '../../assets/index.less'; @@ -72,7 +72,7 @@ const Demo = () => { > {({ columnIndex, rowIndex, style }) => (
(
( = 1, - }, + { [expandedClsName]: indent >= 1 }, )} style={{ ...style, @@ -201,7 +199,7 @@ const BodyRow = ( return ( - className={cls(columnClassName, classNames.cell)} + className={clsx(columnClassName, classNames.cell)} style={styles.cell} ellipsis={column.ellipsis} align={column.align} @@ -232,7 +230,7 @@ const BodyRow = ( expandRowNode = ( { data: readonly RecordType[]; @@ -136,7 +136,7 @@ const Body = (props: BodyProps) => { {/* Measure body column width with additional hidden col */} {measureColumnWidth && ( diff --git a/src/Cell/index.tsx b/src/Cell/index.tsx index d10d1bce6..7353aec6d 100644 --- a/src/Cell/index.tsx +++ b/src/Cell/index.tsx @@ -1,5 +1,5 @@ import { useContext } from '@rc-component/context'; -import cls from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import TableContext from '../context/TableContext'; import devRenderTimes from '../hooks/useRenderTimes'; @@ -218,7 +218,7 @@ const Cell = (props: CellProps) => { }); // >>>>> ClassName - const mergedClassName = cls( + const mergedClassName = clsx( cellPrefixCls, className, { diff --git a/src/FixedHolder/index.tsx b/src/FixedHolder/index.tsx index e5d0f0075..419637eaa 100644 --- a/src/FixedHolder/index.tsx +++ b/src/FixedHolder/index.tsx @@ -1,5 +1,5 @@ import { useContext } from '@rc-component/context'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import { fillRef } from '@rc-component/util/lib/ref'; import * as React from 'react'; import { useMemo } from 'react'; @@ -175,7 +175,7 @@ const FixedHolder = React.forwardRef>((pro ...style, }} ref={setScrollRef} - className={classNames(className, { + className={clsx(className, { [stickyClassName]: !!stickyClassName, })} > diff --git a/src/Header/Header.tsx b/src/Header/Header.tsx index d70046744..9af2956c1 100644 --- a/src/Header/Header.tsx +++ b/src/Header/Header.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { clsx } from 'clsx'; import { useContext } from '@rc-component/context'; import TableContext, { responseImmutable } from '../context/TableContext'; import devRenderTimes from '../hooks/useRenderTimes'; @@ -11,7 +12,6 @@ import type { StickyOffsets, } from '../interface'; import HeaderRow from './HeaderRow'; -import cls from 'classnames'; import type { TableProps } from '..'; function parseHeaderRows( @@ -33,7 +33,7 @@ function parseHeaderRows( const colSpans: number[] = columns.filter(Boolean).map(column => { const cell: CellType = { key: column.key, - className: cls(column.className, classNames.cell) || '', + className: clsx(column.className, classNames.cell) || '', style: styles.cell, children: column.title, column, @@ -121,7 +121,7 @@ const Header = (props: HeaderProps) => { return ( {rows.map((row, rowIndex) => { diff --git a/src/Table.tsx b/src/Table.tsx index 1abfd93cd..a8431dc4c 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -25,7 +25,7 @@ */ import type { CompareProps } from '@rc-component/context/lib/Immutable'; -import cls from 'classnames'; +import { clsx } from 'clsx'; import ResizeObserver from '@rc-component/resize-observer'; import { getTargetScrollBarSize } from '@rc-component/util/lib/getScrollBarSize'; import useEvent from '@rc-component/util/lib/hooks/useEvent'; @@ -779,12 +779,8 @@ const Table = ( // >>>>>> Unique table groupTableNode = (
@@ -817,7 +813,7 @@ const Table = ( let fullTable = (
( {...dataProps} > {title && ( - + {title(mergedData)} )}
{groupTableNode}
{footer && ( - + {footer(mergedData)} )} diff --git a/src/VirtualTable/BodyLine.tsx b/src/VirtualTable/BodyLine.tsx index 5e6acc2dd..f3a507353 100644 --- a/src/VirtualTable/BodyLine.tsx +++ b/src/VirtualTable/BodyLine.tsx @@ -1,5 +1,5 @@ import { useContext } from '@rc-component/context'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import Cell from '../Cell'; import TableContext, { responseImmutable } from '../context/TableContext'; @@ -58,7 +58,7 @@ const BodyLine = React.forwardRef((props, ref) => expandRowNode = ( ((props, ref) => {expandContent} @@ -95,7 +93,7 @@ const BodyLine = React.forwardRef((props, ref) => {...restProps} data-row-key={rowKey} ref={rowSupportExpand ? null : ref} - className={classNames(className, `${prefixCls}-row`, rowProps?.className, { + className={clsx(className, `${prefixCls}-row`, rowProps?.className, { [`${prefixCls}-row-extra`]: extra, })} style={{ ...rowStyle, ...rowProps?.style }} diff --git a/src/VirtualTable/VirtualCell.tsx b/src/VirtualTable/VirtualCell.tsx index f8204f429..ebcfff4ad 100644 --- a/src/VirtualTable/VirtualCell.tsx +++ b/src/VirtualTable/VirtualCell.tsx @@ -1,5 +1,5 @@ import { useContext } from '@rc-component/context'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import { getCellProps } from '../Body/BodyRow'; import Cell from '../Cell'; @@ -113,7 +113,7 @@ const VirtualCell = (props: VirtualCellProps) => { return ( ( ( record: RecordType, @@ -116,7 +116,7 @@ export default function useRowInfo( expandable: mergedExpandable, rowProps: { ...rowProps, - className: classNames(computeRowClassName, rowProps?.className), + className: clsx(computeRowClassName, rowProps?.className), onClick, }, }; diff --git a/src/stickyScrollBar.tsx b/src/stickyScrollBar.tsx index c9878c8ce..c19209294 100644 --- a/src/stickyScrollBar.tsx +++ b/src/stickyScrollBar.tsx @@ -1,5 +1,5 @@ import { useContext } from '@rc-component/context'; -import classNames from 'classnames'; +import { clsx } from 'clsx'; import getScrollBarSize from '@rc-component/util/lib/getScrollBarSize'; import * as React from 'react'; import TableContext from './context/TableContext'; @@ -196,7 +196,7 @@ const StickyScrollBar: React.ForwardRefRenderFunction({ @@ -12,7 +12,7 @@ export function renderExpandIcon({ const expandClassName = `${prefixCls}-row-expand-icon`; if (!expandable) { - return ; + return ; } const onClick: React.MouseEventHandler = event => { @@ -22,7 +22,7 @@ export function renderExpandIcon({ return (