Skip to content

Commit 4903c7f

Browse files
committed
Add guard to prevent load() from overwriting set() values
If set() is called before load() completes, the #hasBeenSet flag prevents load() from overwriting the user's value with stale data. https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
1 parent 878d684 commit 4903c7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

frontend/viewer/src/lib/utils/project-storage.svelte.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class StorageProp {
5252
#key: string;
5353
#backend: IPreferencesService;
5454
#value = $state<string>('');
55+
#hasBeenSet = false;
5556

5657
constructor(projectCode: string, key: string, backend: IPreferencesService) {
5758
this.#projectCode = projectCode;
@@ -65,6 +66,7 @@ class StorageProp {
6566
}
6667

6768
async set(value: string): Promise<void> {
69+
this.#hasBeenSet = true;
6870
this.#value = value;
6971
const storageKey = this.getStorageKey();
7072
if (value) {
@@ -80,7 +82,9 @@ class StorageProp {
8082

8183
private async load(): Promise<void> {
8284
const value = await this.#backend.get(this.getStorageKey());
83-
this.#value = value ?? '';
85+
if (!this.#hasBeenSet) {
86+
this.#value = value ?? '';
87+
}
8488
}
8589
}
8690

0 commit comments

Comments
 (0)