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 <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2021-03-06 19:06:42 +05:30 committed by GitHub
parent bf97414530
commit 07e71a8071
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -1008,7 +1008,13 @@ class App extends React.Component<ExcalidrawProps, AppState> {
}
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