Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: do not mutate tags directly

thecodrrb5b3451691bc
diff --git a/packages/core/collections/tags.js b/packages/core/collections/tags.js
index 5ec05b2ce..8cb07edae 100644
--- a/packages/core/collections/tags.js
+++ b/packages/core/collections/tags.js
@@ -11,11 +11,13 @@ export default class Tags {
async add(id) {
if (!id || id.trim().length <= 0) return;
- let tag = (await this._collection.getItem(id)) || {
- id,
- title: id,
- count: 0
- };
+ let tag = this._collection.exists(id)
+ ? { ...(await this._collection.getItem(id)) }
+ : {
+ id,
+ title: id,
+ count: 0
+ };
tag.count++;
await this._collection.addItem(tag);
}
@@ -28,6 +30,7 @@ export default class Tags {
if (!id || id.trim().length <= 0) return;
let tag = this._collection.getItem(id);
if (!tag) return;
+ tag = { ...tag };
tag.count--;
if (tag.count === 0) {
await this._collection.removeItem(id);