From d90ac998aaf27df7468259574af219b8d6ae9cf8 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 17 Mar 2026 23:23:03 +0100 Subject: [PATCH] Handle incorrect usage of subscribe in stores If the unsubscribe function is called multiple times the indexOf function will return -1 which will end up removing random other subscription callbacks. Prevent the incorrect callabck removial in this case. --- packages/web_ui/src/store/default_mod_pack_store.ts | 5 ++++- packages/web_ui/src/store/export_locale_stores.ts | 5 ++++- packages/web_ui/src/store/export_prototype_metadata_store.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/web_ui/src/store/default_mod_pack_store.ts b/packages/web_ui/src/store/default_mod_pack_store.ts index 275066cb..bd4686fd 100644 --- a/packages/web_ui/src/store/default_mod_pack_store.ts +++ b/packages/web_ui/src/store/default_mod_pack_store.ts @@ -35,7 +35,10 @@ class DefaultModPackStore { this.callbacks.push(callback); this.refCount += 1; return () => { - this.callbacks.splice(this.callbacks.indexOf(callback), 1); + const index = this.callbacks.indexOf(callback); + if (index !== -1) { + this.callbacks.splice(index, 1); + } this.refCount -= 1; if (this.refCount === 0) { clearInterval(this.interval); diff --git a/packages/web_ui/src/store/export_locale_stores.ts b/packages/web_ui/src/store/export_locale_stores.ts index ef07b4b7..f0a10ada 100644 --- a/packages/web_ui/src/store/export_locale_stores.ts +++ b/packages/web_ui/src/store/export_locale_stores.ts @@ -47,7 +47,10 @@ class ExportLocaleStore { } cacheEntry.callbacks.push(callback); return () => { - cacheEntry.callbacks.splice(cacheEntry.callbacks.indexOf(callback), 1); + const index = cacheEntry.callbacks.indexOf(callback); + if (index !== -1) { + cacheEntry.callbacks.splice(index, 1); + } }; } diff --git a/packages/web_ui/src/store/export_prototype_metadata_store.ts b/packages/web_ui/src/store/export_prototype_metadata_store.ts index 17030032..c8222ac6 100644 --- a/packages/web_ui/src/store/export_prototype_metadata_store.ts +++ b/packages/web_ui/src/store/export_prototype_metadata_store.ts @@ -112,7 +112,10 @@ class ExportPrototypeMetadataStore { } cacheEntry.callbacks.push(callback); return () => { - cacheEntry.callbacks.splice(cacheEntry.callbacks.indexOf(callback), 1); + const index = cacheEntry.callbacks.indexOf(callback); + if (index !== -1) { + cacheEntry.callbacks.splice(index, 1); + } }; }