From 3ac82877f7053ed12f734ca439403bbe65b26271 Mon Sep 17 00:00:00 2001 From: bdeshi Date: Sun, 2 Aug 2026 22:01:00 +0600 Subject: [PATCH] two concurrent saves could land out of order --- main.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index eef8d9e..1991180 100644 --- a/main.js +++ b/main.js @@ -97,11 +97,20 @@ module.exports = class RibbonClasp extends Plugin { this.mergeNewItems(ribbon); } + // a drag saves, and the dom change it makes wakes the observer up, which can + // save again before the first one has finished writing. queue them instead. + save() { + this.writing = Promise.resolve(this.writing) + .catch(() => {}) + .then(() => this.saveData(this.settings)); + return this.writing; + } + recordOrder(ribbon) { const ids = ribbon.items.map((item) => item.id); if (this.sameOrder(ids, this.settings.order)) return; this.settings.order = ids; - this.saveData(this.settings); + this.save(); } // only append icons we haven't seen before instead of overwriting the @@ -113,7 +122,7 @@ module.exports = class RibbonClasp extends Plugin { const newIds = ribbon.items.map((item) => item.id).filter((id) => !known.has(id)); if (newIds.length === 0) return; this.settings.order = [...this.settings.order, ...newIds]; - this.saveData(this.settings); + this.save(); } sameOrder(a, b) {