diff --git a/src/components/App.tsx b/src/components/App.tsx index a47aea270f..dd6df0cb53 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -224,7 +224,6 @@ import { SidebarName, SidebarTabName, ScrollConstraints, - NormalizedZoomValue, } from "../types"; import { debounce, @@ -459,13 +458,9 @@ class App extends React.Component { lastPointerDown: React.PointerEvent | null = null; lastPointerUp: React.PointerEvent | PointerEvent | null = null; lastViewportPosition = { x: 0, y: 0 }; - private memoizedScrollConstraints: { - input: { - scrollConstraints: AppState["scrollConstraints"]; - values: Omit, "zoom"> & { zoom: NormalizedZoomValue }; - }; - result: ReturnType; - } | null = null; + private memoizedScrollConstraints: ReturnType< + App["calculateConstraints"] + > | null = null; constructor(props: AppProps) { super(props); @@ -1657,17 +1652,21 @@ class App extends React.Component { } = this.state; // TODO: this could be replaced with memoization function like _.memoize() - const calculatedConstraints = - isShallowEqual( - scrollConstraints, - this.memoizedScrollConstraints?.input.scrollConstraints ?? {}, - ) && + const canUseMemoizedConstraints = + isShallowEqual(scrollConstraints, prevState.scrollConstraints ?? {}) && isShallowEqual( { width, height, zoom: zoom.value, cursorButton }, - this.memoizedScrollConstraints?.input.values ?? {}, - ) && - this.memoizedScrollConstraints - ? this.memoizedScrollConstraints.result + { + width: prevState.width, + height: prevState.height, + zoom: prevState.zoom.value, + cursorButton: prevState.cursorButton, + } ?? {}, + ); + + const calculatedConstraints = + canUseMemoizedConstraints && !!this.memoizedScrollConstraints + ? this.memoizedScrollConstraints : this.calculateConstraints({ scrollConstraints, width, @@ -1676,13 +1675,7 @@ class App extends React.Component { cursorButton, }); - this.memoizedScrollConstraints = { - input: { - scrollConstraints, - values: { width, height, zoom: zoom.value, cursorButton }, - }, - result: calculatedConstraints, - }; + this.memoizedScrollConstraints = calculatedConstraints; const constrainedScrollValues = this.constrainScrollValues({ ...calculatedConstraints,