From 07e71a80718a7729977ea0409671e54b2dcd31c1 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Sat, 6 Mar 2021 19:06:42 +0530 Subject: [PATCH] fix: Reduce the scroll debounce timeout to 100ms and update only if offset changes (#3182) * fix: Reduce the scroll debounce timeout to 100ms so offsets get updated faster when the container scrolled fixes https://github.com/excalidraw/excalidraw/issues/3175 * update changelog * update offsets only when if it changes * up * Update src/components/App.tsx Co-authored-by: David Luzar --- src/components/App.tsx | 8 +++++++- src/constants.ts | 2 +- src/packages/excalidraw/CHANGELOG.md | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index ddaa552e..cb65a860 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1008,7 +1008,13 @@ class App extends React.Component { } private onScroll = debounce(() => { - this.setState({ ...this.getCanvasOffsets() }); + const { offsetTop, offsetLeft } = this.getCanvasOffsets(); + this.setState((state) => { + if (state.offsetLeft === offsetLeft && state.offsetTop === offsetTop) { + return null; + } + return { offsetTop, offsetLeft }; + }); }, SCROLL_TIMEOUT); // Copy/paste diff --git a/src/constants.ts b/src/constants.ts index 2a7c66fb..94711354 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -94,7 +94,7 @@ export const TOUCH_CTX_MENU_TIMEOUT = 500; export const TITLE_TIMEOUT = 10000; export const TOAST_TIMEOUT = 5000; export const VERSION_TIMEOUT = 30000; -export const SCROLL_TIMEOUT = 500; +export const SCROLL_TIMEOUT = 100; export const ZOOM_STEP = 0.1; diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md index dd073044..5d0d992b 100644 --- a/src/packages/excalidraw/CHANGELOG.md +++ b/src/packages/excalidraw/CHANGELOG.md @@ -12,6 +12,16 @@ The change should be grouped under one of the below section and must contain PR Please add the latest change on the top under the correct section. --> +## Unreleased + +## Excalidraw API + +### Fixes + +- Reduce the scroll debounce timeout to `100ms` so `offsets` gets updated faster if changed when container scrolled [#3182](https://github.com/excalidraw/excalidraw/pull/3182). + +--- + ## 0.4.1 ## Excalidraw API