fix(canvas): significant lag when dragging (fixes #967)

This commit is contained in:
Elian Doran 2025-01-18 00:14:31 +02:00
parent 7cf1fbf088
commit 2167948509
No known key found for this signature in database
2 changed files with 16 additions and 7 deletions

View File

@ -43,6 +43,14 @@ export default class SpacedUpdate {
return allSaved;
}
/**
* Normally {@link scheduleUpdate()} would actually trigger the update only once per {@link updateInterval}. If the method is called 200 times within 20s, it will execute only 20 times.
* Sometimes, if the updates are continuous this would cause a performance impact. Resetting the time ensures that the calls to {@link triggerUpdate} have stopped before actually triggering an update.
*/
resetUpdateTimer() {
this.lastUpdated = Date.now();
}
triggerUpdate() {
if (!this.changed) {
return;

View File

@ -383,9 +383,10 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
/**
* save content to backend
* spacedUpdate is kind of a debouncer.
*/
saveData() {
// Since Excalidraw sends an enormous amount of events, wait for them to stop before actually saving.
this.spacedUpdate.resetUpdateTimer();
this.spacedUpdate.scheduleUpdate();
}