@@ -8,7 +8,6 @@ import useMount from './useMount';
8
8
import useUpdateLayoutEffect from './useUpdateLayoutEffect' ;
9
9
import isNumberOrTrue from './isNumberOrTrue' ;
10
10
import { RowDataType , ElementOffset } from '../@types/common' ;
11
- import debounce from 'lodash/debounce' ;
12
11
13
12
interface TableDimensionProps < Row , Key > {
14
13
data ?: readonly Row [ ] ;
@@ -59,7 +58,6 @@ const useTableDimension = <Row extends RowDataType, Key>(props: TableDimensionPr
59
58
children,
60
59
expandedRowKeys,
61
60
showHeader,
62
- bordered,
63
61
onTableResizeChange,
64
62
onTableScroll
65
63
} = props ;
@@ -257,13 +255,21 @@ const useTableDimension = <Row extends RowDataType, Key>(props: TableDimensionPr
257
255
calculateTableHeight ( entries [ 0 ] . contentRect . height ) ;
258
256
} ) ;
259
257
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
+ } ;
267
273
resizeObserver . current = new ResizeObserver ( changeTableWidthWhenResize ) ;
268
274
resizeObserver . current . observe ( tableRef ?. current as Element ) ;
269
275
0 commit comments