From 7b6794affdba3caa1f0d31ffa0d556c54966eaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 21 Oct 2021 17:25:56 +0800 Subject: [PATCH] chore: Improve perf of tabs scroll (#433) * chore: Update docs * chore: Perf of scroll list * chore: clean up lint --- docs/examples/overflow.tsx | 2 +- docs/examples/renderTabBar-dragable.tsx | 1 - src/TabNavList/OperationNode.tsx | 29 +++++++++++++++---------- src/TabNavList/index.tsx | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/docs/examples/overflow.tsx b/docs/examples/overflow.tsx index cb941464..42e58133 100644 --- a/docs/examples/overflow.tsx +++ b/docs/examples/overflow.tsx @@ -4,7 +4,7 @@ import '../../assets/index.less'; const tabs: React.ReactElement[] = []; -for (let i = 0; i < 50; i += 1) { +for (let i = 0; i < 200; i += 1) { tabs.push( Content of {i} diff --git a/docs/examples/renderTabBar-dragable.tsx b/docs/examples/renderTabBar-dragable.tsx index 4b43c388..4494b2d3 100644 --- a/docs/examples/renderTabBar-dragable.tsx +++ b/docs/examples/renderTabBar-dragable.tsx @@ -1,4 +1,3 @@ -/* eslint-disable import/no-named-as-default-member */ import React from 'react'; import { DndProvider, DragSource, DropTarget } from 'react-dnd'; import HTML5Backend from 'react-dnd-html5-backend'; diff --git a/src/TabNavList/OperationNode.tsx b/src/TabNavList/OperationNode.tsx index 64d27a7c..b630052e 100644 --- a/src/TabNavList/OperationNode.tsx +++ b/src/TabNavList/OperationNode.tsx @@ -23,6 +23,7 @@ export interface OperationNodeProps { locale?: TabsLocale; removeAriaLabel?: string; onTabClick: (key: React.Key, e: React.MouseEvent | React.KeyboardEvent) => void; + tabMoving?: boolean; } function OperationNode( @@ -76,7 +77,7 @@ function OperationNode( selectedKeys={[selectedKey]} aria-label={dropdownAriaLabel !== undefined ? dropdownAriaLabel : 'expanded dropdown'} > - {tabs.map(tab => { + {tabs.map((tab) => { const removable = editable && tab.closable !== false && !tab.disabled; return ( {/* {tab.tab} */} {tab.tab} - { - removable && - } + )} - ) + ); })} ); function selectOffset(offset: -1 | 1) { - const enabledTabs = tabs.filter(tab => !tab.disabled); - let selectedIndex = enabledTabs.findIndex(tab => tab.key === selectedKey) || 0; + const enabledTabs = tabs.filter((tab) => !tab.disabled); + let selectedIndex = enabledTabs.findIndex((tab) => tab.key === selectedKey) || 0; const len = enabledTabs.length; for (let i = 0; i < len; i += 1) { @@ -178,7 +179,7 @@ function OperationNode( } const overlayClassName = classNames({ - [`${dropdownPrefix}-rtl`]: rtl + [`${dropdownPrefix}-rtl`]: rtl, }); const moreNode: React.ReactElement = mobile ? null : ( @@ -218,4 +219,10 @@ function OperationNode( ); } -export default React.forwardRef(OperationNode); +export default React.memo( + React.forwardRef(OperationNode), + (_, next) => + // https://github.com/ant-design/ant-design/issues/32544 + // We'd better remove syntactic sugar in `rc-menu` since this has perf issue + next.tabMoving, +); diff --git a/src/TabNavList/index.tsx b/src/TabNavList/index.tsx index 81654fe1..3bf307c4 100644 --- a/src/TabNavList/index.tsx +++ b/src/TabNavList/index.tsx @@ -498,6 +498,7 @@ function TabNavList(props: TabNavListProps, ref: React.Ref) { prefixCls={prefixCls} tabs={hiddenTabs} className={!hasDropdown && operationsHiddenClassName} + tabMoving={!!lockAnimation} />