two concurrent saves could land out of order

This commit is contained in:
bdeshi committed 2026-08-02 22:01:00 +06:00
1 parent d3fb5b4383
commit 3ac82877f7
1 file changed
+11 -2
+11 -2
View File
@@ -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) {