diff --git a/packages/core/src/common/PositionCache.ts b/packages/core/src/common/PositionCache.ts index 72a267f5b..cc8aede24 100644 --- a/packages/core/src/common/PositionCache.ts +++ b/packages/core/src/common/PositionCache.ts @@ -99,4 +99,27 @@ export class PositionCache { getHeight(topIndex: number) { return this.bottoms[topIndex] - this.tops[topIndex] } + + similarTo(otherCache: PositionCache) { + return similarNumArrays(this.tops || [], otherCache.tops || []) && + similarNumArrays(this.bottoms || [], otherCache.bottoms || []) && + similarNumArrays(this.lefts || [], otherCache.lefts || []) && + similarNumArrays(this.rights || [], otherCache.rights || []) + } +} + +function similarNumArrays(a: number[], b: number[]): boolean { + const len = a.length + + if (len !== b.length) { + return false + } + + for (let i = 0; i < len; i++) { + if (Math.round(a[i]) !== Math.round(b[i])) { + return false + } + } + + return true } diff --git a/packages/daygrid/src/TableRow.tsx b/packages/daygrid/src/TableRow.tsx index b4c792a29..ff0cccdc5 100644 --- a/packages/daygrid/src/TableRow.tsx +++ b/packages/daygrid/src/TableRow.tsx @@ -318,7 +318,7 @@ export class TableRow extends DateComponent { } updateSizing(isExternalSizingChange) { - let { props, frameElRefs } = this + let { props, state, frameElRefs } = this if ( !props.forPrint && @@ -329,15 +329,23 @@ export class TableRow extends DateComponent { if (frameEls.length) { let originEl = this.rootElRef.current + let newPositionCache = new PositionCache( + originEl, + frameEls, + true, // isHorizontal + false, + ) - this.setState({ // will trigger isCellPositionsChanged... - framePositions: new PositionCache( - originEl, - frameEls, - true, // isHorizontal - false, - ), - }) + if (!state.framePositions || !state.framePositions.similarTo(newPositionCache)) { + this.setState({ // will trigger isCellPositionsChanged... + framePositions: new PositionCache( + originEl, + frameEls, + true, // isHorizontal + false, + ), + }) + } } }