From dfb479156b0237561303c9114f87da2ab317c654 Mon Sep 17 00:00:00 2001 From: whiteand Date: Sun, 17 Jan 2021 01:20:05 +0200 Subject: [PATCH] perf(Table): moved update of scrollbar width to separated macro task. It will cause less time spent in the current macrotask --- source/Table/Table.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/Table/Table.js b/source/Table/Table.js index e0211a8ce..e1c0df238 100644 --- a/source/Table/Table.js +++ b/source/Table/Table.js @@ -263,6 +263,7 @@ export default class Table extends React.PureComponent { this._onScroll = this._onScroll.bind(this); this._onSectionRendered = this._onSectionRendered.bind(this); this._setRef = this._setRef.bind(this); + this._updateTimeoutHandle = null; } forceUpdateGrid() { @@ -353,7 +354,21 @@ export default class Table extends React.PureComponent { } componentDidUpdate() { - this._setScrollbarWidth(); + if (this._updateTimeoutHandle) { + clearTimeout(this._updateTimeoutHandle); + } + + // We move this update to separated macro-task in order to not create long executed tasks + this._updateTimeoutHandle = setTimeout(() => { + this._updateTimeoutHandle = null; + this._setScrollbarWidth(); + }, 0); + } + + componentWillUnmount() { + if (this._updateTimeoutHandle) { + clearTimeout(this._updateTimeoutHandle); + } } render() {