throttle attempt

This commit is contained in:
zsviczian 2023-02-26 21:25:46 +01:00
parent 1d5e865da1
commit 48deb68326
2 changed files with 36 additions and 23 deletions

View File

@ -1283,7 +1283,10 @@ class App extends React.Component<AppProps, AppState> {
}
}
private renderScene = () => {
private renderScene = (
renderingElements: NonDeletedExcalidrawElement[] = [],
shouldCacheIgnoreZoom: boolean | null = null,
) => {
const cursorButton: {
[id: string]: string | undefined;
} = {};
@ -1321,9 +1324,10 @@ class App extends React.Component<AppProps, AppState> {
cursorButton[socketId] = user.button;
});
const renderingElements = this.scene
.getNonDeletedElements()
.filter((element) => {
renderingElements =
renderingElements.length > 0
? renderingElements
: this.scene.getNonDeletedElements().filter((element) => {
if (isImageElement(element)) {
if (
// not placed on canvas yet (but in elements array)
@ -1363,7 +1367,10 @@ class App extends React.Component<AppProps, AppState> {
remoteSelectedElementIds,
remotePointerUsernames: pointerUsernames,
remotePointerUserStates: pointerUserStates,
shouldCacheIgnoreZoom: this.state.shouldCacheIgnoreZoom,
shouldCacheIgnoreZoom:
shouldCacheIgnoreZoom === null
? this.state.shouldCacheIgnoreZoom
: shouldCacheIgnoreZoom,
theme: this.state.theme,
imageCache: this.imageCache,
isExporting: false,
@ -6367,7 +6374,13 @@ class App extends React.Component<AppProps, AppState> {
private resetShouldCacheIgnoreZoomDebounced = debounce(() => {
if (!this.unmounted) {
this.setState({ shouldCacheIgnoreZoom: false });
//generateElementWithCanvas
const elements = this.scene.getNonDeletedElements();
for (let i = 0; i < elements.length; i += 200) {
const chunk = elements.slice(i, i + 200);
setTimeout(() => this.renderScene(chunk, false));
}
setTimeout(() => this.setState({ shouldCacheIgnoreZoom: false }));
}
}, 300);