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