@@ -8,7 +8,6 @@ import useMount from './useMount';
88import useUpdateLayoutEffect from './useUpdateLayoutEffect' ;
99import isNumberOrTrue from './isNumberOrTrue' ;
1010import { RowDataType , ElementOffset } from '../@types/common' ;
11- import debounce from 'lodash/debounce' ;
1211
1312interface TableDimensionProps < Row , Key > {
1413 data ?: readonly Row [ ] ;
@@ -59,7 +58,6 @@ const useTableDimension = <Row extends RowDataType, Key>(props: TableDimensionPr
5958 children,
6059 expandedRowKeys,
6160 showHeader,
62- bordered,
6361 onTableResizeChange,
6462 onTableScroll
6563 } = props ;
@@ -257,13 +255,21 @@ const useTableDimension = <Row extends RowDataType, Key>(props: TableDimensionPr
257255 calculateTableHeight ( entries [ 0 ] . contentRect . height ) ;
258256 } ) ;
259257 containerResizeObserver . current . observe ( tableRef ?. current ?. parentNode as Element ) ;
260- const changeTableWidthWhenResize = debounce ( entries => {
261- const { width } = entries [ 0 ] . contentRect ;
262- // bordered table width is 1px larger than the container width. fix: #405 #404
263- const widthWithBorder = width + 2 ;
264-
265- calculateTableWidth ( bordered ? widthWithBorder : width ) ;
266- } , 20 ) ;
258+ let idleCallbackId : null | number = null ;
259+ const changeTableWidthWhenResize = function ( entries ) {
260+ if ( idleCallbackId ) {
261+ window . cancelIdleCallback ( idleCallbackId ) ;
262+ }
263+ idleCallbackId = window . requestIdleCallback ( deadline => {
264+ // if idle time >= 10ms, then we can judge other tasks have completed
265+ if ( deadline . timeRemaining ( ) >= 10 ) {
266+ idleCallbackId = null ;
267+ calculateTableWidth ( entries [ 0 ] . contentRect . width ) ;
268+ } else {
269+ changeTableWidthWhenResize ( entries ) ;
270+ }
271+ } ) ;
272+ } ;
267273 resizeObserver . current = new ResizeObserver ( changeTableWidthWhenResize ) ;
268274 resizeObserver . current . observe ( tableRef ?. current as Element ) ;
269275
0 commit comments